[RESOLVED] Sort Recordset On Form
I have added the ability to search records on a form. I am trying to sort the results of the search by related field the search was conducted on, but I am having problems because the sort property doesn't seem to do anything.
VB Code:
Dim strDatabaseField As String
Dim intBookmark As Integer
If cboCriteriaField.text = "" Then
lblResults.Caption = "* Select A Search Criteria"
ElseIf txtSearch.text = "" Then
lblResults.Caption = "* Enter Search Text"
Else
'
' Save the information of before the query.
'
intBookmark = Data.Recordset.AbsolutePosition + 1
strDatabaseField = Replace(cboCriteriaField.text, " ", "")
Data.Recordset.Sort = strDatabaseField ' Sort the recordset before searching
Data.Recordset.FindFirst strDatabaseField & " LIKE '" & Sql(txtSearch.text) & "*'"
If Data.Recordset.NoMatch Then
'
' Restore the previous settings
'
Data.Recordset.Move intBookmark - 1
lblResults.Caption = "* No Matchs Found"
Else
lblResults.Caption = ""
txtSearch.text = ""
End If
End If
The initial recordset of the data control is to a single table using the following SQL.
VB Code:
Me.Data.RecordSource = "SELECT * FROM tblArchive"
Is there any reason the sort property isn't actually sorting anything?
Re: Sort Recordset On Form
Is your recordset's property cursorlocation set to AdUseClient?
Maybe you must call recordset.moveFirst() before search !!
Re: Sort Recordset On Form
Sounds like your using the ADO Data control. Its a bound object and in VB 6 bound objects always give you more headaches then manually writting the code in pure ADO.
Re: Sort Recordset On Form
It is the ADO Data control. I will just write the code in pure ADO as you suggest Rob.
Re: [RESOLVED] Sort Recordset On Form
You have just saved yourself many headaches. :)
If you need any help with ADO let us know. ;)