G
Guest
Hi all,
I have a search form that allows the user to look up records based on
multiple fields. However, I am wondering if I can set up some type of
wildcard search, so that if the first couple letters are entered, it will
still bring up all matching records. For example, if I was looking for the
last name "Smith" but only entered "Smi" it would still bring in the "Smith"
records. However, I would only want to apply this for text searches, not for
phone number or zip code. Here is the code that I currently have:
Private Sub Command6_Click()
Dim strWhere As String
strWhere = "True"
If Not IsNull(Me.LastName) Then
strWhere = strWhere & " AND ShipTo_LName=""" & Me.LastName & """"
End If
If Not IsNull(Me.ZipCode) Then
strWhere = strWhere & " And ShipTo_ZIP5='" & Me.ZipCode & "'"
End If
If Not IsNull(Me.PhoneNum) Then
strWhere = strWhere & " And ShipTo_Phone='" & Me.PhoneNum & "'"
End If
If Not IsNull(Me.Email) Then
strWhere = strWhere & " And ShipTo_Email='" & Me.Email & "'"
End If
If Not IsNull(Me.OrderNum) Then
strWhere = strWhere & " And Order_ID=" & Me.OrderNum
End If
DoCmd.OpenForm "INQUIRY_MAIN_View", , , strWhere
DoCmd.Close acForm, "INQUIRY_MAIN"
End Sub
Also, what could I add to this code so that if there are no matching
records, I could have a message pop up that says there are no matching
records? Currently I get an error message Runtime 2427 (no matching value)
Thank you for your help!
-gary
I have a search form that allows the user to look up records based on
multiple fields. However, I am wondering if I can set up some type of
wildcard search, so that if the first couple letters are entered, it will
still bring up all matching records. For example, if I was looking for the
last name "Smith" but only entered "Smi" it would still bring in the "Smith"
records. However, I would only want to apply this for text searches, not for
phone number or zip code. Here is the code that I currently have:
Private Sub Command6_Click()
Dim strWhere As String
strWhere = "True"
If Not IsNull(Me.LastName) Then
strWhere = strWhere & " AND ShipTo_LName=""" & Me.LastName & """"
End If
If Not IsNull(Me.ZipCode) Then
strWhere = strWhere & " And ShipTo_ZIP5='" & Me.ZipCode & "'"
End If
If Not IsNull(Me.PhoneNum) Then
strWhere = strWhere & " And ShipTo_Phone='" & Me.PhoneNum & "'"
End If
If Not IsNull(Me.Email) Then
strWhere = strWhere & " And ShipTo_Email='" & Me.Email & "'"
End If
If Not IsNull(Me.OrderNum) Then
strWhere = strWhere & " And Order_ID=" & Me.OrderNum
End If
DoCmd.OpenForm "INQUIRY_MAIN_View", , , strWhere
DoCmd.Close acForm, "INQUIRY_MAIN"
End Sub
Also, what could I add to this code so that if there are no matching
records, I could have a message pop up that says there are no matching
records? Currently I get an error message Runtime 2427 (no matching value)
Thank you for your help!
-gary