T
Tony Williams
I have a search form with a control called txtsearch. When the user enters
characters into txtsearch and then presses Enter my form shows all the
records which include the characters. However all the controls I'm searching
are text fields but there is one control that is a number field, txtrefnbr
and I want to include that in my search. How do I change my code to add the
number field to the criteria. Here is my code:
Private Sub txtSearch_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
'execute search
Debug.Print "Search for " & Me.txtSearch.Value
Me.RecordSource = "SELECT * FROM [qrysearchcomplaint] WHERE
[txtcomplainant] like ""*" & Me.txtSearch.Value & "*"" or [txtbusinessname]
like ""*" & Me.txtSearch.Value & "*"" or [txtsurname] like ""*" &
Me.txtSearch.Value & "*"""
Me.btnShowAll.Visible = True
Me.lblSearch.Visible = False
If Me.RecordsetClone.RecordCount = 0 Then
Me.RecordSource = "qrysearchcomplaint"
Me.txtSearch.SetFocus
Me.btnShowAll.Visible = False
MsgBox "No records found for your search criteria",
vbInformation, strAppName
Me.lblSearch.Visible = True
End If
End If
End Sub
characters into txtsearch and then presses Enter my form shows all the
records which include the characters. However all the controls I'm searching
are text fields but there is one control that is a number field, txtrefnbr
and I want to include that in my search. How do I change my code to add the
number field to the criteria. Here is my code:
Private Sub txtSearch_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
'execute search
Debug.Print "Search for " & Me.txtSearch.Value
Me.RecordSource = "SELECT * FROM [qrysearchcomplaint] WHERE
[txtcomplainant] like ""*" & Me.txtSearch.Value & "*"" or [txtbusinessname]
like ""*" & Me.txtSearch.Value & "*"" or [txtsurname] like ""*" &
Me.txtSearch.Value & "*"""
Me.btnShowAll.Visible = True
Me.lblSearch.Visible = False
If Me.RecordsetClone.RecordCount = 0 Then
Me.RecordSource = "qrysearchcomplaint"
Me.txtSearch.SetFocus
Me.btnShowAll.Visible = False
MsgBox "No records found for your search criteria",
vbInformation, strAppName
Me.lblSearch.Visible = True
End If
End If
End Sub