I have a search on my form that will jump users to the matching record of a Code they enter. Right now, if you enter a code that isn't in the recordset, it jumps you back to the first record. But it isn't obvious that it has done that, you might think it found the code and you're on that record if you don't look at the code. I want it to display a message if that code wasn't found.
Here is my code.
I replaced the line in the If rs.EOF then to a MsgBox ("Code Not Found") but that didn't work when I entered a bogus code, it still just jumped me back to the first record.
Here is my code.
Code:
Private Sub FindButton_Click()
Dim rs As Object
Dim answer As String
Set rs = Me.Recordset.Clone
answer = "D" & Me.FindCode.Value
rs.FindFirst "[Code]=" & "'" & answer & "'"
If rs.EOF Then
DoCmd.GoToRecord , , acNewRec
Else
Me.Bookmark = rs.Bookmark
End If
Me.FindCode.Value = ""
Me.FindButton.SetFocus
End Sub
I replaced the line in the If rs.EOF then to a MsgBox ("Code Not Found") but that didn't work when I entered a bogus code, it still just jumped me back to the first record.