I am receiving an error message: Compile error: User-defined type not defined. I am trying to make a message box appear when there are no results.
Here is my code:
Can someone help? I desperately need it.
Here is my code:
Code:
Private Sub btnSearchContacts_Click()
Dim strSQL As Variant
Dim l_strAnd As String
Dim RS As DAO.Recordset
Set RS = Me.RecordsetCl
RS.RecordCount
If (Me.txtSearchClientID & "" = "") And (Me.txtSearchFirst & "" = "") And (Me.txtSearchLast & "" = "") And (Me.txtSearchCompany1 & "" = "") Then
' If the search criteria are Null, use the whole table as the RecordSource.
Me.RecordSource = "Accounts"
Else
l_strAnd = ""
strSQL = "SELECT distinctrow Accounts.* " _
& "FROM Accounts INNER JOIN ClientInformation " _
& "ON Accounts.[Account ID] = ClientInformation.[Account ID] " _
& "WHERE "
If Me.txtSearchClientID.Value & "" <> "" Then
strSQL = strSQL & l_strAnd & "ClientInformation.[Client ID] = " & Me.txtSearchClientID
l_strAnd = " AND "
End If
If Me.txtSearchCompany1.Value <> "" Then
strSQL = strSQL & l_strAnd _
& "Accounts.[Company] Like '" _
& Me.txtSearchCompany1.Value & "*'"
l_strAnd = " AND "
End If
If Me.txtSearchFirst.Value <> "" Then
strSQL = strSQL & l_strAnd _
& "ClientInformation.[First Name] Like '" _
& Me.txtSearchFirst.Value & "'"
l_strAnd = " AND "
End If
If Me.txtSearchLast.Value <> "" Then
strSQL = strSQL & l_strAnd _
& "ClientInformation.[Last Name] Like '" & Me.txtSearchLast.Value & "'"
End If
On Error Resume Next
Me.RecordSource = strSQL
If Me.RecordCount = 0 Then
MsgBox "No records matching filter."
Me.RecordSource = "Accounts"
RS.Close
Set RS = Nothing
End If
End If
End Sub
Can someone help? I desperately need it.