Filter that displays a message box when nothing is found

c02dm

Registered User.
Local time
Today, 18:55
Joined
Apr 12, 2005
Messages
18
Hi,

I'm trying to search for a last name, but if the name can't be found i want it to return a message box saying "There are no customers with that name". I've tried using an if statement but it seems to run past the code for the filter and just display the message box each time even if the customer is in the table or not. Can anyone please help. Here is my code to implement the filter.

Private Sub cmdFilterByName_Click()

Dim strName As String
Dim strFilter As String

strName = txtLastName & "*"

strFilter = "[LastName] like '" & strName & "'"

DoCmd.ApplyFilter , strFilter

End Sub

Thanks in advance.

Dan
 
Searching the forum is a great way to discover and learn the answers to your Access programming questions.

Code:
If Me.RecordsetClone.RecordCount = 0 Then
        MsgBox "There are zero records in the data source!", vbInformation, "No Records Found"
        Me.Filter = ""
        Me.FilterOn = False
    End If

On second thought...I think that you need to incorporate a DCount() to see if there are any records found for the selected search. Search around for there are plenty of examples floating around this forum.
 
Last edited:
Can we see the whole code?
maybe the problems within the logic, of your If statement?
 

Users who are viewing this thread

Back
Top Bottom