Hi
I created a search command button. But it's not working for me
Can anyone help?
I created a search command button. But it's not working for me
Code:
Private Sub cmSearch_Click()
Dim qdf As DAO.querydef
Dim LSQL As String
Dim LSearchString As String
If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."
Else
Set qdf = CurrentDb.QueryDefs("querySearch")
LSearchString = txtSearchString
'Filter results based on search string
LSQL = "select * from Products"
LSQL = LSQL & " where Descriptions LIKE '*" & LSearchString & "*'"
Debug.Print LSQL
qdf.sql = LSQL
If DCount("*", "querysearch", "Descriptions Like '*" & LSearchString & "*'") > 0 Then
DoCmd.OpenQuery "querySearch"
Else
MsgBox "There are no records with Search string " & vbCrLf & vbTab & "--->" & LSearchString & "<---"
End If
'Clear search string
'txtSearchString = ""
'MsgBox "Results have been filtered. All Descriptions containing " & LSearchString & "."
End If
End Sub
End Sub
Can anyone help?