Link to home
Start Free TrialLog in
Avatar of shambalad
shambaladFlag for United States of America

asked on

Error 2110 - Access can’t move the focus to the control

I am working on a form in Access 2010, and getting a 2110 error. I’ve looked at some of the posts from the past dealing with this error, but still can’t seem to make sense of why this is happening. This is not a subform/form issues. All controls are unlocked and enabled. The odd thing is that the ‘set focus’ appears to work most of the time.
I have attached a small accdb which replicates the error.
Basically, the form has a combo box and a list box. Both controls have the same row source, which is a table. The combo box is set to auto-expand, so as characters are keyed in, the next valid value in the list is filled in. For each combo box KeyUp event, a sub is called that sets the list box to the same value as the text box. (I don’t know if this arrangement has any real practical value, but that’s a different topic for discussion).
Anyway, all seems to work fine so long as I key in valid values in the combo box. But if I key in a backspace, I get the 2110 error. Within the sub that is getting the error, the actual key code value shouldn’t be relevant (at least I don’t think it should).
Hopefully these screen shots will give you a better idea of what is happening.
This 1st picture is how things look when the form first opens.User generated imageIn the 2nd picture, I have keyed an ‘f’ into the combo box. Note how the list box has ‘synced’ up to the combo box value.User generated imageKeyed in an ‘r’.User generated imageKeyed in an ‘e’User generated imageKeyed in a backspace, got the error.User generated image What should be happening here is that there is now the value ‘fre’ in the combo box, the list box should be set to the first value starting with ‘fre’. It’s not getting that far though, because of the 2110 error. At least that is the way it appears to me; sometimes when I’ve spent too long looking at the same code/error, I can start missing things.
Here is the errant sub:

Public Sub ScrollListBox(ctlLst As Control, lngIndex As Long)
      Const strProcedure As String = "ScrollListBox"
      Dim LngThumb As Long
      Dim hWndSB As Long
      Dim lngRet As Long
10    On Error GoTo ErrorHandler

20    If lngIndex < 0 Then
30       lngIndex = 0
40    End If                        'If lngIndex < 0

50    With ctlLst
60       If Not .ControlType = acListBox Then
70          GoTo ExitSub
80       End If                     'If Not .ControlType = acListBox
         
         ' SetFocus to Listbox
90       .SetFocus                  '<==== 2110 Error here
         
         ' Now get the listbox's handle
100      hWndSB = GetFocus
         
         ' Set the window's ScrollBar position
110      LngThumb = MakeDWord(SB_THUMBPOSITION, CInt(lngIndex))
120      lngRet = SendMessage(hWndSB, WM_VSCROLL, LngThumb, 0&)
         
         ' Select that row in the listbox
130      .Selected(lngIndex) = True
140   End With                      'With ctlLst

ExitSub:
150   On Error Resume Next
160   Err.Clear
170   Exit Sub

ErrorHandler:
180   MsgBox "Error: " & Err.Description & " (" & Err & ") in procedure " & mstrModule & "." & strProcedure & " at line " & Erl
190   Resume ExitSub
End Sub

Open in new window

If anyone can shed some light on what is happening here I would be most grateful.
Sync-Controls-Demo.accdb
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

just wondering why you need to synch the combo box with the list box.
the combo box can also lead you to the item as you typed in the combo box.

see this revision
Sync-Controls-Demo.accdb
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shambalad

ASKER

It suggests to me that there is a different locking mechanism going on when the combo box has a value it cannot validly 'auto-expand' on. I have another idea I'm going to try to see if I can't get around it.
It appears to be a problem with having the LimitToList property set to true. The combo box value (e.g. "zz") is invalid, which kicks off a NotInList event, and Access isn't going to let the focus loose until the error is resolved. I'm going to play with this a little more to see if I can't resolve the issue to Access's satisfaction within the code.
which kicks off a NotInList event
That makes sense ... perhaps Access "locks" the focus during the NIL event, and doesn't allow you to refocus any other control? Not sure about that ...
That's what appears to be happening. I working on work-around right now.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm going to close this question out. This setup appears to be working correctly. The 2110 issue has definitely been resolved. Although I essentially resolved this problem myself, I would like to extend some credit to LSM. His comment ,
<"it does so everytime I enter an invalid key combination">,
caused me to redirect my focus to the NotInList event, which in turn, lead to the ultimate solution.
Thank you,
Todd
That sounds reasonable ...
Stated my reasoning in previous post. Thanks to all on this forum for your help.
Todd