Search form is not searching

sokolln

Registered User.
Local time
Today, 15:45
Joined
Jun 4, 2008
Messages
21
I have a form with a button that when pressed brings up a search form. The search form searches a query from which the primary form data is extracted. No errors are being reported with the search, but the search is not functioning properly. I get a message saying the search has filtered the results, but this is not true.

Here is my code:
Code:
Private Sub cmdSearch_Click()
    If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
        MsgBox "You must select a field to search."
 
    ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
        MsgBox "You must enter search text."
 
    Else
 
        'Generate search criteria
        GCriteria = "Replace ([" & cboSearchField.Value & "], chr(39), '')" & " LIKE '*" & Replace(txtSearchString, "'", "") & "*'"
 
        'Filter [TEST Master Form by Ult Parent] based on search criteria
        'Form_TEST Master Form by Ult Parent.RecordSource' = "select * from [Ultimate Parent Table Query - Organizational Profile Report] where " & GCriteria
        'Form_TEST Master Form by Ult Parent.Caption' = "[Ultimate Parent Table Query - Organizational Profile Report] (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"""
 
        'Close frmSearch
        DoCmd.Close acForm, "frmSearch"
 
        MsgBox "Results have been filtered."
 
    End If
 
End Sub

Any clue what's going on? Any help is appreciated.
 
I realized the silly error I had with the apostrophes. Those are gone but now I'm getting a Compile Error: Sub or Function not Defined. I think this is coming up because the form I am referencing has spaces in it. I don't want to change the name of the form because it is referenced many times throughout the database.

Here is the updated code:

Code:
Private Sub cmdSearch_Click()
    If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
        MsgBox "You must select a field to search."
 
    ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
        MsgBox "You must enter search text."
 
    Else
 
        'Generate search criteria
        GCriteria = "Replace ([" & cboSearchField.Value & "], chr(39), '')" & " LIKE '*" & Replace(txtSearchString, "'", "") & "*'"
 
        'Filter [TEST Master Form by Ult Parent] based on search criteria
        Form_("[TEST Master Form by Ult Parent].RecordSource") = "select * from [Ultimate Parent Table Query - Organizational Profile Report] where " & GCriteria
        Form_("[TEST Master Form by Ult Parent].Caption") = "[Ultimate Parent Table Query - Organizational Profile Report] (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"""
 
        'Close frmSearch
        DoCmd.Close acForm, "frmSearch"
 
        MsgBox "Results have been filtered."
 
    End If
 
End Sub
 

Users who are viewing this thread

Back
Top Bottom