Results 1 to 9 of 9
  1. #1
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58

    runtime error '2110'

    i have an error message in my search box on my form that I can't correct. Strangely this error message ONLY comes up when I enter a wrd that contains the letter (lower case) 'i'. It's really weird!
    The message I get is: Run-time error '2110':
    Microsoft Access can't move the focus to the control SearchResults.

    the problem is in this code (see text in BLUE).
    Cany anyone help?


    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


    '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

  2. #2
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    From the 2007 error code site.

    Microsoft Office Access can't move the focus to the control. The control may be a type that can't receive the focus, such as a label. The control's Visible property may be set to No. The control's Enabled property may be set to No.


    http://www.fmsinc.com/microsoftacces...ption2007.html


    Dale

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Something doesn't look right in the code.
    vSearchString = SearchFor.Text
    Here you are getting the uncommitted text from the textbox.



    I would try the following changes (if the list box multi-select property is set to NONE):
    Code:
       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.Selected(1) = True
          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.Selected(1) = True
       Me.SearchResults.SetFocus
    This is hard to troubleshoot without being able to run the code. Have you put a breakpoint on the first IF statement, then stepped through the code to see on which line the error occurred?

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by pbouk View Post

    Me.SearchResults = Me.SearchResults.ItemData(1)
    Me.SearchResults.SetFocus
    You have to first SetFocus to the Listbox and then make a selection, which is why you're popping an error. Also, you should note that the Index of an Item in a Listbox is Zero-based, so the first row would be ItemData(0), not ItemData(1).

    To send Focus to the Listbox and have it select the first item, I'd reverse the two lines (and replace the 1 with a 0)

    Code:
    SearchResults.SetFocus
    Me.SearchResults = Me.SearchResults.ItemData(0)

    Linq ;0)>

  5. #5
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    Quote Originally Posted by Missinglinq View Post
    You have to first SetFocus to the Listbox and then make a selection, which is why you're popping an error. Also, you should note that the Index of an Item in a Listbox is Zero-based, so the first row would be ItemData(0), not ItemData(1).

    To send Focus to the Listbox and have it select the first item, I'd reverse the two lines (and replace the 1 with a 0)

    Code:
    SearchResults.SetFocus
    Me.SearchResults = Me.SearchResults.ItemData(0)

    Linq ;0)>

    thanks for this! It worked very well.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>

  7. #7
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    Folks, unfortunately I was wrong, the code changes you offered don't work!
    It's still playing up when I type in "i".
    I tried to follow ssanfu's suggestion to step through the code, but I'm such a novice I'm not really sure what I'm looking for. All I know is the debugger tells me the code in blue (see first post) is the problem.

    This code was taken from here:
    http://www.access-programmers.co.uk/...d.php?t=188663
    I am using the improved procedure that is posted after the first set of code.
    I've also posted this to the person who wrote the code...but thought others might have some suggestions.

    Thanks for any assistance.

  8. #8
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    Thanks June7, it's still not working for me though. I've tried this before I think. I only add it in the Company field of the rowsource/query right?
    Attachment 12577

  9. #9
    cadlum is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    1
    So I came across the same program and was using it for the same purpose and was having the same problem... small world right?

    Found a fix for it though! (for access 2010)

    Open the form you are using, go into design view, highlight the search box and open the property sheet. Under the Other tab, there is an option for 'Allow AutoCorrect'. Turn that to No and lowercase i finally works. Enjoy!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  2. runtime error 2110
    By Mclaren in forum Programming
    Replies: 9
    Last Post: 07-07-2011, 01:02 PM
  3. Replies: 0
    Last Post: 02-22-2011, 04:18 PM
  4. Error in Runtime Only
    By drunkinmunki in forum Programming
    Replies: 7
    Last Post: 12-16-2010, 03:43 PM
  5. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums