Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting records by alphabetical order

Status
Not open for further replies.

hanosm

Technical User
Jul 25, 2003
52
GB
I know this is a REALLY easy one, but I can't seem to find the answer!

How do you sort the records shown on a form, by alphabetical order using VB Code?

For example, I have an form that shows all client information, but it is currently showing them by ClientID order (Autonumber). How do I order the records by surname?
 
Place this e.g. in the On Mouse down event of a Label above a Text Box:

Me!YourTextBoxName.SetFocus
If Button = 1 Then
DoCmd.RunCommand acCmdSortAscending
Else
DoCmd.RunCommand acCmdSortDescending
End If

Left clicking the label will sort Ascending, right click will sort Descending.

Bill
 
EDSKI

This does not seem to be working for some reason. The first record displayed is still the first record by ClientID. I tried placing the code in the Form Load, Form Open and even Form Current sections. No luck.


BILLPOWER

I haven't tried this as I need the records sorted before the form is used, but I like the code and will no doubt use it in future! Thanks.
 
In the On Load event of your Form:

Me!YourTextBoxName.SetFocus
DoCmd.RunCommand acCmdSortAscending
Me!AnotherTextBoxName.SetFocus 'if needed

Cheers

Bill
 
BILLPOWER

Works like a charm!

Thnaks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top