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

How to alert user when this code gets no match

Status
Not open for further replies.

dlsd619

Technical User
Jul 11, 2007
14
0
0
US
I use the following code in a text box to jump to a certain record. The way it is now, if there is no record that matches, then it jumps to the first record in the table.

How can I trap or identify when this code returns no match?

I know it would be easy if it were a combo box (NotInList), but there is just to many records to use a combo.

Thank you for any suggestions.

Private Sub txtDateSearch_AfterUpdate()
On Error GoTo Err_txtDateSearch_AfterUpdate
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ActivityDate] = #" & Me![txtDateSearch] & "#"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Exit_txtDateSearch_AfterUpdate:
Exit Sub
Err_txtDateSearch_AfterUpdate:
MsgBox Err.Number & Err.Description
Resume Exit_txtDateSearch_AfterUpdate
End Sub
 
after the findfirst
if rs.nomatch then
do something
end if
 
Okay...I am still stuck a little. I use the following code, and it works as far as letting the user know there was no match. However, it still goes to the first record. How can I get it to do nothing? Do I need to do something in the Before_Update event?

Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ActivityDate] = #" & Me![txtDateSearch] & "#"
If rs.NoMatch Then
MsgBox "No Match"
Response = acDataErrContinue
Else
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End If
 
untested


Dim rs As Object
dim varBookMark as variant
Set rs = Me.Recordset.Clone
varBookMark = rs.bookmark
rs.FindFirst "[ActivityDate] = #" & Me![txtDateSearch] & "#"
If rs.NoMatch Then
MsgBox "No Match"
Response = acDataErrContinue
me.bookmark = varBookMark
Else
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top