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 eg 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
试试这个: Me.frmResultsSub.Form.fldA.Width = 600
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:
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. rowSource
to any SQL statement. You will have to handle sync with main form data but it is very simple. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.