RonNCmale
03-18-2008, 08:57 PM
I have the following code behind a search button on my form. When it is clicked it list which field to search and search text. It works great on the form, I can advance the forms records and see each one. I need additional code to be able to print these results to a report. Or another way to get the same results.
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 a search string."
Else
'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
'Filter frmSTG based on search criteria
Form_frmSTG.RecordSource = "select * from STG where " & GCriteria
Form_frmSTG.Caption = "STG (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSTGSearch"
MsgBox "Results have been filtered."
End If
End Sub
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 a search string."
Else
'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
'Filter frmSTG based on search criteria
Form_frmSTG.RecordSource = "select * from STG where " & GCriteria
Form_frmSTG.Caption = "STG (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSTGSearch"
MsgBox "Results have been filtered."
End If
End Sub