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

Sorting results of a Search

Status
Not open for further replies.

jsdavis

MIS
Apr 4, 2007
8
US
Hello,

I have a question about getting results sorted. Here is my code:

Private Sub cmdSearch_Click()

If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."

ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."

'If Searching by Member # - from separate form/table
ElseIf Me.cboSearchField.Value = "Member_Number" Then
'Generate search criteria
GCriteria = cboSearchField.Value & " Like '*" & txtSearchString & "*'"
'Send records that match criteria to listbox
Form_SCITSearch.cmbSearchResults.RowSource = "select * from Members where " & GCriteria
'Force SearchResults combo box to drop down
DoCmd.GoToControl "cmbSearchResults"
SendKeys "%{Down}"


Else

'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
'SORT RECORDS RETURNED TO ALPHABETICAL BASED ON LAST NAME OF RECORD
???????
'Send records that match criteria to listbox
Form_SCITSearch.cmbSearchResults.RowSource = "select * from Files where " & GCriteria
'Force SearchResults combo box to drop down
DoCmd.GoToControl "cmbSearchResults"
SendKeys "%{Down}"

End If

End Sub

I hope this makes sense. I put a note in where I think I need to add the code but I'm not sure if that's exactly the place. The first section of code is actually irrelevant at this point. Please let me know of any suggestions you may have.

Thank you! :)
 
Why not simply add an ORDER BY clause to the SQL code of the RowSource property ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top