Hi Karen,
OK, so is OrderByOn only set in VBA? It's not a property
of the form?
I *think* so. I'm not completely positive. Bas is the real
expert, I'm just his personal assistant.
And Jeff, I do end up using queries on the tables to get
my data and get it sorted.
That's good. Most experts believe basing forms on queries
or SQL statements is better than directly on the table
itself.
It just seemed like I should be able to just use the
properties of the form and not build a query every time
for the control source (not that it takes forever!).
Well remember that you can change the form's record source
at any time as well as apply filters and sort orders.
There are lots of ways to accomplish your goal, my point
was if the ONLY way you're going to display the data in
that form is by Last Name than just base it on a saved
query and not mess with an OrderBy property at all.
If you want to completely change the record source and/or
change sort orders you can do this "on the fly" in VBA.
For example, I have a continuous form list of products.
The form is based on a simple saved query listing all
products. Through command buttons and combo boxes I change
the record source of the form like so:
Me.Form.RecordSource = "SELECT tblProducts.* FROM
tblProducts ORDER BY ProductName;"
Me.Form.Requery
(This shows me all the products in alphabetical order by
name)
Or:
Me.Form.RecordSource = "SELECT tblProducts.* FROM
tblProducts WHERE (((tblProducts.[Active]) = Yes)) ORDER
BY ProductName;"
Me.Form.Requery
(This shows me all Active products in alphabetical order
by name)
Or:
Me.Form.RecordSource = "SELECT tblProducts.* FROM
tblProducts WHERE (((tblProducts.[Active]) = No)) ORDER BY
ProductName;"
(This shows me all Inactive products in alphabetical order
by name)
So by all means you can change the underlying record
source at any time without having to create an additional
saved query.
Hope that helps,
Jeff Conrad
Bend, Oregon
Jeff Conrad said:
Hi,
Not sure I can completely help, but I'll give it a shot.
I'm sure there are probably lots of ways to solve this.
1. Do you always want to sort by Last Name?
Why not just base the form on a saved query that sorts by last name?
2. I'm assuming you went to the form's properties and Put LastName on the
"Order By" line. You open the form, but it still is not showing the
employees in alphabetical order by last name. Correct?
Try adding this line to the Form's Open event:
Me.Form.OrderByOn = True
Save the form and see if that solves the problem.
3. On some forms (usually continuous) I give the user
the option to sort
by
various fields. For example, say I have two fields called Report Group
Number and Report Group Name. I make two small command buttons over each
field in the Form Header and use the little A->Z and Z- A bitmaps.
I code the button Click events like so:
Private Sub cmdSortNameAscending_Click()
Me.txtReportGroupName.SetFocus
DoCmd.RunCommand acCmdSortAscending
End Sub
Private Sub cmdSortNameDescending_Click()
Me.txtReportGroupName.SetFocus
DoCmd.RunCommand acCmdSortDescending
End Sub
Hope that gives you some ideas to try.
Jeff Conrad
Bend, Oregon
I have gotten into the habit of never using the
OrderBy property on a
form
as it seems to do nothing.
I'm using Access 2003, I've set the control source of a form to a table,
e.g. Employees and let's say I want to sort by Last Name so I've tried
these
forms in the OrderBy property of the form, all had no effect
"LastName"
"[LastName]"
Is there a bug or am I just missing something really obvious?
.