Using Gcriteria to Open report from Form

angeljtm

New member
Local time
Today, 12:28
Joined
Apr 29, 2008
Messages
4
Hello!

I've been trying to get this to work for awhile and have had no success. I am following this example http://www.techonthenet.com/access/forms/search2.php. I am trying to search records on a form by using a pop up form with the following code:
Private Sub cmdSearch_Click()
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
Gcriteriasec = cboSearchField1.Value & " LIKE '*" & txtSearchString1 & "*'"
If Not (Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True) Then
If Len(cboSearchField1) = 0 Or IsNull(cboSearchField1) = True Then
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
Form_frmServiceForm.RecordSource = "select * from [Service Table] where " & GCriteria
DoCmd.Close acForm, "frmSearch"
MsgBox "Results have been filtered."
Else
If Not (Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True) Then
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
Gcriteriasec = cboSearchField1.Value & " LIKE '*" & txtSearchString1 & "*'"
Form_frmServiceForm.RecordSource = "select * from [Service Table] where " & _
GCriteria & " And " & Gcriteriasec
DoCmd.Close acForm, "frmSearch"
MsgBox "Results have been filtered."
End If
End If
End If
End Sub


This allows me to have two text boxes to search from. The form is then "filtered" to only show the records that contain the text searched for (such as name, region, result). I then want to click my generate report button to create a report that will only show the records that contain the text that was searched for using the pop up form. A person can enter no critera, one of the criteria, or both of the criteria.

DoCmd.OpenReport "Daily Service report", acViewPreview, , GCriteria
This command works to view a report containing the first criteria, but should a person search using both text boxes I don't know how to create code so they can generate a report to show their results.

Please help!!
 

Users who are viewing this thread

Back
Top Bottom