1
votes

I have a form, frmResults, which contains a subform control, frmResultsSub.

frmResultsSub is a subform control which contains a query instead of a form. In other words, its SourceObject property is set to the query, "Query.qrySearch"

Is there any way I can reference the fields of this query to e.g. to centre text or change field width?

I've tried these statements in the Open Event for frmResults, but neither was successful:

Me!frmResultsSub.fldA.Width = 600
Me.frmResultsSub.fldA.Width = 600
3

3 Answers

1
votes

I don't think you can adjust column width on a query using VBA. You can however solve your problem using one of those methods:

  • create a form (AutoForm is ok) and make its default view as Datasheet. then use that form as the source of your subform control. that will be visually identical to your current solution.
  • use a listBox instead of a subform. It's quite versatile and you can easily set the listbox rowSource to any SQL statement. You will have to handle sync with main form data but it is very simple.
1
votes

Try this: Me.frmResultsSub.Form.fldA.Width = 600

1
votes

Reference the fldA field in the query the same as you would if it were the name of a textbox on a form contained in that frmResultsSub subform control.

Put this in On Load and verify it shows you the field name instead of triggering an error ...

MsgBox Me!frmResultsSub!fldA.name

Once you have that working correctly, you can work with the column's properties. During On Load, adjust its ColumnWidth property to change its width ...

Me!frmResultsSub!fldA.ColumnWidth = 600

That should allow you to set the width. But you also mentioned text alignment, and I don't see how to do that for a query column unless you create an actual form based on the query.