Hi
I created a search button. However, I encounted a problem when I click on the search button, there is a message box shows: "Compile error: User-defined Type not defined". I have checked it, and I didn't find any problem in the following code. Can anyone let know what is wrong?
Thanks
I created a search button. However, I encounted a problem when I click on the search button, there is a message box shows: "Compile error: User-defined Type not defined". I have checked it, and I didn't find any problem in the following code. Can anyone let know what is wrong?
Code:
Private Sub cmSearches_Click()
On Error GoTo Err_cmSearches_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 StockRecord"
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
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_cmSearches_Click:
Exit Sub
Err_cmSearches_Click:
MsgBox Err.Description
Resume Exit_cmSearches_Click
End Sub
Thanks