Strange issue Dynamically searching multiple fields.

sethgecko1977

New member
Local time
Today, 16:56
Joined
Jul 1, 2013
Messages
2
I'm by no means an access guru, I ended up being roped into designing a database for a friend.
I've used the dynamically searching multiple fields tutorial posted by John Big Booty on this website, this has worked fine,
The users upgraded from Access 2007 to Access 2010 a few weeks ago (don't know if its related to the problem but thought i should mention it.)
Now if i type in the search box it works as normal until i start a search by typing the letter "I" it throws up a Runtime error 2110 Access cannot move the focus SearchResults.
If i type any letter before the I it works, its only when i start a search beginning with I. Also it works fine in Access 2013 but fails in Access 2010?
I'm a novice (perhaps lower than that) at VB so any help is appreciated.
The code is as follows:

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

'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_SearchAll
SrchText.Value = vSearchString

'Requery the List Box to show the latest results for the text entered in Text Box SearchFor
Me.SearchResults.Requery


'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor
If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus
'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of the List Box
DoCmd.Requery
'Returns the cursor to the the end of the text in Text Box SearchFor,
'and restores trailing space lost when focus is shifted to the list box
Me.SearchFor = vSearchString
Me.SearchFor.SetFocus
Me.SearchFor.SelStart = Me.SearchFor.SelLength

Exit Sub
End If

'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus !!!DEBUGGING HIGHLIGHTS THIS LINE!!!

'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of the List Box
DoCmd.Requery

'Returns the cursor to the the end of the text in Text Box SearchFor
Me.SearchFor.SetFocus

If Not IsNull(Len(Me.SearchFor)) Then
Me.SearchFor.SelStart = Len(Me.SearchFor)
End If
End Sub
 
I had the same problem, but I found this code in some of the chat about this routine. Apparently for some wierd reason, only the lower case "i" doesn't work. Put this code in the onKeyPress event on the SearchFor field, it works fine:

Private Sub Text1_Keypress(KeyAscii as Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
 

Users who are viewing this thread

Back
Top Bottom