Using .findfirst and signaling no result (1 Viewer)

jjake

Registered User.
Local time
Today, 06:39
Joined
Oct 8, 2015
Messages
291
I'm using the following code to look a user up by a pin code which works fine. But how do i alert the user if a match is not found. I tried to create a blank record as the first record in the table and match by a blank textbox but couldn't get it to work


Code:
Private Sub cmdSearch_Click()

           
  Dim strCriteria As String
 
  Dim rst As DAO.Recordset
 
  Set rst = Me.RecordsetClone
 
 
 
  strCriteria = "[ConCode] = '" & Me![ConCodeLookup] & "'"
 
  rst.FindFirst strCriteria
  
 Me.Bookmark = rst.Bookmark
 

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:39
Joined
Oct 29, 2018
Messages
21,467
Hi. Not sure where you got that code; but normally, you would see it with an If/Then block. For example:
Code:
...
rst.FindFirst strCriteria
If rst.NoMatch Then
    MsgBox "No match found."
Else
    Me.Bookmark = rst.Bookmark
End If
...
 

jjake

Registered User.
Local time
Today, 06:39
Joined
Oct 8, 2015
Messages
291
Perfect thanks.
 

Users who are viewing this thread

Top Bottom