When using a Database, a crucial function is to be able to find specific records. You can do this using the Find and Seek functions of the Data control.
Data1.Recordset.FindFirst criteria
Data1.Recordset.FindLast criteria
Data1.Recordset.FindNext criteria
Data1.Recordset.FindPrevious criteria
Data1.Recordset.Seek comparison, key1, key2...key13
Find method |
Begins searching at Search direction |
FindFirst |
Beginning of recordset End of recordset |
FindLast |
End of recordset Beginning of recordset |
FindNext |
Current record End of recordset |
FindPrevious |
Current record Beginning of recordset |
The criteria property of the Find methods is quite simple, and takes the following format:
FieldName = Value
If FieldName contains a space, it must be contained by ":
Data1.Recordset.FindFirst "ISBN = '0-0131985-2-1'"
To see if either of these method has found an item check the NoMatch property:
If Data1.Recordset.NoMatch = True Then
Msgbox "No match found"
End If
As the FindFirst method will move you to the beginning of the recordset if there is no match, you should bookmark the position, and return to it if no match is found.
Dim varBookmark As Variant
varBookmark = datTitles.Recordset.Bookmark
datTitles.Recordset.FindFirst "ISBN = '0-0131985-2-12'"
If datTitles.Recordset.NoMatch = True Then
datTitles.Recordset.Bookmark = varBookmark
MsgBox "No match found"
End If
Comments