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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible for me to use VBA to sort records ??? 2

Status
Not open for further replies.

e1k4l3cs

MIS
Nov 11, 2002
56
0
0
SG
Is it possible for me to use VBA to sort records ??? Eg: I need to sort our 3 different fields: ANumber, BNumber & CNumber. More priority will be given to "ANumber", "BNumber" then "CNumber". How should I go about programming it ??? Should I use VBA or ADO ???

A Million Thanks...
 
You can always sort in a query with the Order By clause.

You can sort an ADO recordset that you create with vba code.

What are you going to do with the data once it is sorted?
 
There are various techniques in vba

me.orderby

this is in a table
gotocontrol("nameofcontrol")
docmd.runcommand accmdsortdescending

hope it helps

jason
 
Ermm... I am sorting base on priority...

As for the "me.orderby" code, can I have a more complete example ??? Thx...
 
In the following example I open the companies table and then sort by the service control, followed by another control.

Sub Docmd1()
DoCmd.OpenTable "Companies"
DoCmd.GoToControl "Service"
DoCmd.RunCommand acCmdSortDescending
DoCmd.GoToControl "DateEntered"
DoCmd.RunCommand acCmdSortAscending
End Sub

For the me.orderby

Create agrouped option group control and place as many options as necesssary. Give the value 1 2 3 etc

then type equivalent to the following code in the after update event

Private Sub grpSortBy_AfterUpdate()
'code to change the order of the records based on the
'selection in the option group grpSortBy
Select Case grpSortBy.Value
Case 1
'code to order by the CompanyName field
Me.OrderBy = "CompanyName"
Case 2
'code to order by the ContactName field
Me.OrderBy = "ContactName"
Case 3
'code to order by the City and CompanyName fields
Me.OrderBy = "City, CompanyName"
Case 4
'code to order by the Country, City and CompanyName fields
Me.OrderBy = "Country, City, CompanyName"
Case 5
'code to order by the Country, City and CompanyName fields
Me.OrderBy = "phone"

End Select

Regards


Jason
 
I understood all ur other cases but not this

'code to order by the Country, City and CompanyName fields
Me.OrderBy = "phone"

Is it typo or wat ???

Thanks a lot...

Kelvin
 
May I also know which object is the "grpSortBy" refering to ???

Thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top