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!

Help with rs.NoMatch code

Status
Not open for further replies.

dlsd619

Technical User
Jul 11, 2007
14
0
0
US
I need help with the following code. I need it to be able to handle the After_Update event when the text box is a Null, or if there is no match I would like to just cancel the whole process.

Such as:
If rs.NoMatch Then
MsgBox "No Match"
"Cancel entire After_Update procedure"
Cancel = True gives me a syntex error.

Maybe there is something wrong with my code. Thanks for any help I can get on this. Or suggestions on how I should do it.

Private Sub txtDateSearch_AfterUpdate()
On Error GoTo Err_txtDateSearch_AfterUpdate
Form_Current
Form.DataEntry = False
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ActivityDate] = #" & Me![txtDateSearch] & "#"
If rs.NoMatch Then
MsgBox "There is no match for your search", vbCritical
Else
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.txtDateSearch = Null
Me.tblActivities_Subform.SetFocus
End If
Exit_txtDateSearch_AfterUpdate:
Exit Sub
Err_txtDateSearch_AfterUpdate:
If Err.Number = 3075 Then
Exit Sub
Else
MsgBox Err.Number & Err.Description
Resume Exit_txtDateSearch_AfterUpdate
End If
End Sub

 
Presumably txtDateSearch is not bound, so just exit the sub (After Update does not have a Cancel). You may wish to set Data Entry to True before you exit, if that is the normal state, even though it seems a little odd.

If you put something like this at the start of the sub, it should exit when there is nothing to search for:

Code:
If Trim(txtDateSearch & "")="" Then Exit Sub

It is usually best to format dates to year, month, day. Unless the computer uses American date format, dates can cause problems.
 
or:
Code:
[blue]   [purple][b]If Trim(Me!txtDateSearch & "") <> "" Then[/b][/purple]
      Set rs = Me.Recordset.Clone
      
      [purple][b]If Not rs.BOF Then[/b][/purple]
         rs.FindFirst "[ActivityDate] = #" & Me![txtDateSearch] & "#"
         
         If rs.NoMatch Then
             MsgBox "There is no match for your search", vbCritical
         Else
             Me.Bookmark = rs.Bookmark
             Me.txtDateSearch = Null
             Me.tblActivities_Subform.SetFocus
         End If
      End If
      
      Set rs = Nothing
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top