Please help me locate precisely where the new code should be inserted in the existing code. Does it go right before the line Me.SearchResults.SetFocus?
Private Sub SearchFor_Change()
'Create a string (text) variable
Dim vSearchString As String
'Populate the string variable with the text entered in the Text Box SearchFor
vSearchString = "" & SearchFor.Text
Not yet fixed -- most likely due to my inexperience. I inserted the 2 new code lines you suggested (searchstring = "" & SearchFor.Text and searchstring = "" & SearchFor.value). But I still get the same runtime error 2110, when I enter small "i". Am I also to include the code (changing to upper case) that you suggested earlier? If so, where?Code:''with this code , it works ''''Populate the string variable with the text entered in the Text Box SearchFor searchstring = "" & Search For.Text ''at the same time - does not work normally 'Populate the string variable with the text entered in the Text Box SearchFor searchstring = "" & Search For.value ''perhaps the error has already been fixed
Private Sub SearchFor_KeyPress(KeyAscii As Integer)
End Sub
Private Sub SearchFor_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
I have all of those settings checked and still did not have any problems. Were yours unchecked?I also cannot replicate your problem. I wonder though if it's spell checking. Try turning off Capitalize first letter File | Options | Proofing |Autocorrect Options
'Create a string (text) variable
Dim vSearchString As String
'Populate the string variable with the text entered in the Text Box SearchFor
vSearchString = RTrim(SearchFor.Text)
Me.SearchResults.RowSource = "SELECT TBL_Client_Basic_Info.[First Name], TBL_Client_Basic_Info.[Last Name], " & _
"TBL_Client_Basic_Info.[Street Address], TBL_Client_Basic_Info.[Client ID] " & _
"FROM TBL_Client_Basic_Info " & _
"WHERE TBL_Client_Basic_Info.[First Name] Like " & Chr(34) & "*" & vSearchString & "*" & Chr(34) & _
" Or TBL_Client_Basic_Info.[Last Name] Like " & Chr(34) & "*" & vSearchString & "*" & Chr(34) & _
" ORDER BY TBL_Client_Basic_Info.[First Name];"
'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(0)
If Len(Me.SearchFor & "") > 0 Then
Me.SearchFor.SelStart = Len(Me.SearchFor)
End If
"WHERE TBL_Client_Basic_Info.[First Name] Like " & Chr(34) & "*" & vSearchString & "*" & Chr(34) & _ " Or TBL_Client_Basic_Info.[Last Name] Like " & Chr(34) & "*" & vSearchString & "*" & Chr(34) & _
" WHERE TBL_Client_Basic_Info.[First Name] Like "'*" & vSearchString & "*'" & _
" Or TBL_Client_Basic_Info.[Last Name] Like "'*" & vSearchString & "*'" & _
Wow! It worked, it worked, it worked. You provided such an easy-to-follow and elegant solution. Really appreciated.Don't think you've put the code suggested by Shanemac51 in the right place. Post #26, get rid of your new code that starts 'New Sub routine to convert ANSI to character string
In the search form properties sheet, select the search field and click the ellipsis (...) On Key Press event. Pick Code Builder.
The code module will open and you will get this:
Code:Private Sub SearchFor_KeyPress(KeyAscii As Integer) End Sub
Add the code line so it looks like this: (this is a one-line version of Shanemac51's code)
Code:Private Sub SearchFor_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii))) End Sub
You will find that all characters entered in the search box will become upper case. It's a work-around, I don't know what the issue with the lower case "i" actually is.
Your search form code is adapted from here: Dynamically search multiple fields | Access World Forums (access-programmers.co.uk)
That's fine until you are searching for a surname such as O'Connor when a run time error will occur." WHERE TBL_Client_Basic_Info.[First Name] Like "'*" & vSearchString & "*'" & _ " Or TBL_Client_Basic_Info.[Last Name] Like "'*" & vSearchString & "*'" & _
Don't have any O'Connor in our client pool, but have an O'Riley which worked as expected (no run-time error).That's fine until you are searching for a surname such as O'Connor when a run time error will occur.