Can you suggest what and where in the code I would enter this?I was asking whether one can actually set focus to a control when it already has the focus.
I've just tried on a test DB of mine and it appears you can.
Can you suggest what and where in the code I would enter this?I was asking whether one can actually set focus to a control when it already has the focus.
I've just tried on a test DB of mine and it appears you can.
But there's one exception to this: if the string starts with a lower case letter i, the next letter typed is placed before rather than after the i. (If the string starts with an upper case I this fluke does not happen.) This is not a computer or keyboard bug,
I've just entered all combination pairs of letters into the search box and it is only the lower case i that creates the problem. Could it be a virus problem rather than a coding issue? What is a "handler" for the characters, and how might I investigate this?whatever the code is - why is there only one letter, what is it guilty of, there may be a handler for the characters being entered
I meant the eventI've just entered all combination pairs of letters into the search box
Private Sub ShipRegion_KeyPress(KeyAscii As Integer)
Dim strCharacter As String
' Convert ANSI value to character string.
str Character = Chr(KeyAscii)
' ' ' ' Convert character to upper case, then to ANSI value.
KeyAscii = Asc(UCase(strCharacter))
End Sub
I entered (by copy-paste) your suggested new code just after the line End If (See following). This seems to have stopped the leftward shift of the "i", but now I get these messages when I enter any and all characters into the search box. I suspect I entered the new code in the wrong place. Can you help me correct this?I meant the event
Code:Private Sub ShipRegion_KeyPress(KeyAscii As Integer) Dim strCharacter As String ' Convert ANSI value to character string. str Character = Chr(KeyAscii) ' ' ' ' Convert character to upper case, then to ANSI value. KeyAscii = Asc(UCase(strCharacter)) End Sub
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
'New Sub routine to convert ANSI to character string
Private Sub ShipRegion_KeyPress(KeyAscii As Integer)
Dim strCharacter As String
' Convert ANSI value to character string.
Str Character = Chr(KeyAscii)
' ' ' ' Convert character to upper case, then to ANSI value.
KeyAscii = Asc(UCase(strCharacter))
End Sub
'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
The error message says: "Expected End Sub."I entered (by copy-paste) your suggested new code just after the line End If (See following). This seems to have stopped the leftward shift of the "i", but now I get these messages when I enter any and all characters into the search box. I suspect I entered the new code in the wrong place. Can you help me correct this?
View attachment 98592View attachment 98593Code: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 'New Sub routine to convert ANSI to character string Private Sub ShipRegion_KeyPress(KeyAscii As Integer) Dim strCharacter As String ' Convert ANSI value to character string. Str Character = Chr(KeyAscii) ' ' ' ' Convert character to upper case, then to ANSI value. KeyAscii = Asc(UCase(strCharacter)) End Sub '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
Private Sub something...()
End Sub
That would be wonderful. I'll provide a dummy set of client data. Shall I zip the files and attach to this thread, or can I email it to you?I can't replicate your issue using the code you have supplied. Perhaps it's time to provide a copy of your database. Remove any confidential data first.
Hi. I just tried your files, and I didn't get any errors. Just confirm, here's what I did:Whatever time you have to give is appreciated. As I mentioned earlier, I'm a complete novice when it comes to modifying the code, and even some of the properties/macros. My role before I took over maintenance of the db was formatting and other simple changes. So, I'm not really sure how to do what you're asking, i.e., disabling, restoring, etc. I usually just left-shift-click to open the db to see all of its objects and codes, and the go to design view to make changes. The form that is giving problems is FRM_SearchMulti, where the search box is upper left. When I enter small "i" I get Run-time error 2110 with the message "RFP Database can't move to the controlSearchResults." When I press Debug, the following code is displayed:
'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
Me.SearchFor.SetFocus
If Not IsNull(Len(Me.SearchFor)) Then
Me.SearchFor.SelStart = Len(Me.SearchFor)
End If
End Sub
Well, my guess is it's a "Settings" thing. Let me dig around to see if I can find something to make it act weird.Yes you did it correctly. What a puzzle! When I do the same thing, even on other computers (home, food pantry, wife's) I get the funny "i" behavior. A virus perhaps buried in the code, that somehow disappeared at your end???
Yesterday, a forum member, Shanemac51, suggested a work-around by converting Ascii characters to upper case, using the code below. I tried inserting the code into the offending procedure, and it seemed to solve the small "i" problem, but I got other error messages. I suspect that I inserted the new code segment in the wrong place. Is this something you can try for me using the db files I sent to you?Well, my guess is it's a "Settings" thing. Let me dig around to see if I can find something to make it act weird.
Private Sub ShipRegion_KeyPress(KeyAscii As Integer)
Dim strCharacter As String
' Convert ANSI value to character string.
str Character = Chr(KeyAscii)
' ' ' ' Convert character to upper case, then to ANSI value.
KeyAscii = Asc(UCase(strCharacter))
End Sub
It's been working well for the past 6 years, except for one (minor) quirk:
''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