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

Message if Code not found

Status
Not open for further replies.

Ebes1099

Technical User
Jul 8, 2009
156
US
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.
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.
 
How are ya Ebes1099 . . .
Code:
[blue]Change: If rs.[purple]EOF[/purple] Then
To    : If rs.[purple][b]NoMatch[/b][/purple] Then[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top