Private Sub cmdWHSearch_Click()
On Error GoTo Form_Err
'*******************************************************************************
'Code adapted from
'http://www.techonthenet.com/access/forms/search2.php
'The purpose of this code is to match the value in the control "txtSearchString"
'and return all matching records, "like" txtSearchString.
'*******************************************************************************
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
GCriteria = " [" & cboSearchField.Value & "] LIKE '*" & txtSearchString & "*'"
Form_frmWHSearch.RecordSource = "SELECT * FROM tblWarehouse INNER JOIN tblPurchData ON tblWarehouse.WarehouseID=tblPurchData.WarehouseID WHERE " & GCriteria
DoCmd.OpenReport "rptWHSearch", acViewPreview, , GCriteria
DoCmd.RunCommand acCmdFitToWindow
End If
Form_Exit:
Exit Sub
Form_Err:
MsgBox Err.Description
Resume Form_Exit
End Sub