Rick Danger
asked on
vba order by
I have the following code:
Me.OrderBy = "person_id"
Me.OrderByOn = True
where person_id is the form field's control source. However, I wish to use its name instead. Is there a way to do this.
So, for clarity, in the form design, the field on the form has a control source of "person_id" (from the "data" tab), but its name is "field_1" (from the "other" tab).
Me.OrderBy = "person_id"
Me.OrderByOn = True
where person_id is the form field's control source. However, I wish to use its name instead. Is there a way to do this.
So, for clarity, in the form design, the field on the form has a control source of "person_id" (from the "data" tab), but its name is "field_1" (from the "other" tab).
Why not just:
OrderBy = "Field_1"
The OrderBy property tells Access how you'd like to Order your records (obviously). It expects a Field name as the setting.
OrderBy = "Field_1"
The OrderBy property tells Access how you'd like to Order your records (obviously). It expects a Field name as the setting.
Why would you care? And why would you use meaningless values as the Name for a control? When you use the wizard or when you drag fields from the field list, Access assigns the bound field name as the control name. When you click on a control in the ribbon and draw it on the form/report, Access assigns an arbitrary name. You should then change that to something meaningful. Who wants to look at code that references text038 and chk120?
" I wish to use its name instead. "
The OrderBy property requires the name of a Field(s) in the underlying Recordsource of the Form, not the Name of a Control.
mx
The OrderBy property requires the name of a Field(s) in the underlying Recordsource of the Form, not the Name of a Control.
mx
ASKER
acbxyz - thanks for your answer, It works, so I'l happily give you the points, but how would I write this code if I also wanted to choose to sort ascending or descending?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's brilliant. Thanks.
ASKER
Excellent solution, thanks very much.
Me.OrderBy = field_1.ControlSource