With help from members of this forum I have a working search form that checks search criteria against the fields they are associated with. My next step to tackle is to include "keywords" that search for their own set of criteria. For example, I would like the user to be able to search for "Z1" which in turn would search for "CT ME MA NH NJ RI VT" (CT or ME or MA or NH or NJ...) in the requested fields and return any records that match.
Here is the code I'm working with as of now:
Is this possible? Could someone give me an example of how to implement this?
Here is the code I'm working with as of now:
Code:
Sub DoDispatchSearch()
Dim ok As Boolean, sql As String
ok = False
sql = " WHERE "
If Not IsNull(Me.txtSrchSCity) Then
If sql <> " WHERE " Then
sql = sql & " And "
End If
ok = True
sql = sql & "([po_c1] LIKE '" & Me.txtSrchSCity & "' OR [po_c2] LIKE '" & Me.txtSrchSCity & "' OR [po_c3] LIKE '" & Me.txtSrchSCity & "' OR [po_c4] LIKE '" & Me.txtSrchSCity & "' OR [po_c5] LIKE '" & Me.txtSrchSCity & "')"
End If
If Not IsNull(Me.txtSrchSState) Then
If sql <> " WHERE " Then
sql = sql & " And "
End If
ok = True
sql = sql & "([po_s1] LIKE '" & Me.txtSrchSState & "' OR [po_s2] LIKE '" & Me.txtSrchSState & "' OR [po_s3] LIKE '" & Me.txtSrchSState & "' OR [po_s4] LIKE '" & Me.txtSrchSState & "' OR [po_s5] LIKE '" & Me.txtSrchSState & "')"
End If
If Not IsNull(Me.txtSrchCcity) Then
If sql <> " WHERE " Then
sql = sql & " And "
End If
ok = True
sql = sql & "([pd_c1] LIKE '" & Me.txtSrchCcity & "' OR [pd_c2] LIKE '" & Me.txtSrchCcity & "' OR [pd_c3] LIKE '" & Me.txtSrchCcity & "' OR [pd_c4] LIKE '" & Me.txtSrchCcity & "' OR [pd_c5] LIKE '" & Me.txtSrchCcity & "')"
End If
If Not IsNull(Me.txtSrchCState) Then
If sql <> " WHERE " Then
sql = sql & " And "
End If
ok = True
sql = sql & "([pd_s1] LIKE '" & Me.txtSrchCState & "' OR [pd_s2] LIKE '" & Me.txtSrchCState & "' OR [pd_s3] LIKE '" & Me.txtSrchCState & "' OR [pd_s4] LIKE '" & Me.txtSrchCState & "' OR [pd_s5] LIKE '" & Me.txtSrchCState & "' OR [pd_so0] LIKE '" & Me.txtSrchCState & "' OR [pd_so1] LIKE '" & Me.txtSrchCState & "' OR [pd_so2] LIKE '" & Me.txtSrchCState & "' OR [pd_so3] LIKE '" & Me.txtSrchCState & "' OR [pd_so4] LIKE '" & Me.txtSrchCState & "' OR [pd_so5] LIKE '" & Me.txtSrchCState & "' OR [pd_so6] LIKE '" & Me.txtSrchCState & "' OR [pd_so7] LIKE '" & Me.txtSrchCState & "' OR [pd_so8] LIKE '" & Me.txtSrchCState & "' OR [pd_so9] LIKE '" & Me.txtSrchCState & "')"
End If
If Me.chkDo_HazMat.Value = True Then
If sql <> " WHERE " Then
sql = sql & " And "
End If
ok = True
sql = sql & "[do_hazmat] = True"
Else
If sql <> " WHERE " Then
sql = sql & " And "
End If
ok = True
sql = sql & "[do_hazmat] = False"
End If
If ok Then
Me.RecordSource = strSELECT & strFROM & sql
Me.Requery
Me.Detail.Visible = True
Me.FormFooter.Visible = True
DoCmd.MoveSize , , 8500, 6000
End If
fitexit:
Exit Sub
fiterr:
MsgBox Error$
Resume fitexit
End Sub
Is this possible? Could someone give me an example of how to implement this?