This Code is based on an unbound mainform with a subform CustomerSelect
place this code behind the search button
'========================
Dim MySQL As String, MyCriteria As String, MyRecordSource As String
Dim ArgCount As Integer
Dim Tmp As Variant
Dim field1 As String
ArgCount = 0
MySQL = "SELECT * FROM Customers WHERE "
MyCriteria = ""
field1 = Me![MyFieldChoice1]
AddToWhere [FindFIRM], "[Company]", MyCriteria, ArgCount
AddToWhere [FindTown], "[Town]", MyCriteria, ArgCount
If MyCriteria = "" Then
MyCriteria = "True"
End If
MyRecordSource = MySQL & MyCriteria
Me![CustomerSelect].Form.RecordSource = MyRecordSource
If Me![CustomerSelect].Form.RecordsetClone.RecordCount = 0 Then
MsgBox "No Clients Found", 48, "Customer Search"
Else
End If
'===============================
You will also require the following private sub which is called from the main search button
'==============================
Private Sub AddToWhere(FieldValue As Variant, FieldName As String, MyCriteria As String, ArgCount As Integer)
If FieldValue <> "" Then
If ArgCount > 0 Then
MyCriteria = MyCriteria & " and "
End If
MyCriteria = (MyCriteria & FieldName & " Like " & Chr(39) & FieldValue & Chr(42) & Chr(39))
ArgCount = ArgCount + 1
End If
End Sub
'==========================
Create textboxes/combos named FindFIRM and FindTown in the unbound main form these are used for the crieria in the searching
u can have any amount of additional search criteria
adding appropraitly named text/combo boxes and the line of code
AddToWhere [FindMyfield1], "[Myfield1]", MyCriteria, ArgCount
AddToWhere [FindMyfield2], "[Myfield2]", MyCriteria, ArgCount
etc
etc
best of luck
Jimmy