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

Set the Sort Order When Opening up a Filtered Form

Status
Not open for further replies.

Quintios

Technical User
Mar 7, 2002
482
US
I have a button that opens up a form. The code behind the button is:

Code:
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stLinkCriteria = "TagTypeID = 6"
    stDocName = "frmTags"
    DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria

Exit_Command10_Click:
    Exit Sub

Err_Command10_Click:
    MsgBox Err.Description
    Resume Exit_Command10_Click

End Sub

How would I set this up so that the form, when opened, is sorted by two criteria: (Ascending) 'SequenceNumber', and then by 'Name'? I assume this would go in the stLinkCriteria, but I don't know how to code it.

Thanks in advance,

Onwards,

Q-
 
There is a Orderby Property on a Form. You can enter the required criteria in here. I think that you could pass the the data in the OpenArgs part of the Docmd.OpenForm action. Then pick that up on the OnOpen action of the form.

If you need more information let me know.

Sandy
 
I should have dug into the help files more...

For anyone that's reading this:

The OrderBy property can be set to the OpenArgs property. The OpenArgs property is set in the DoCmd.OpenForm code that is attached to the button. It comes at the very end.

The syntax for the OrderBy property is: TableName.SortField

So, if you have a table called 'tblEmployees' and wanted to sort on the Field 'LastName', you'd do something like this:

strOpenOrder = "tblEmployees.LastName"

Then put strOpenOrder at the end of your DoCmd.OpenForm code.

Then, in the Open event of the form that you're opening, put the following code:

Me.Orderby = Me.OpenArgs

That's it!! Thanks for the help!
Onwards,

Q-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top