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.
In 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.
Keyed in an ‘r’.
Keyed in an ‘e’
Keyed in a backspace, got the error.
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
150 On Error Resume Next
170 Exit Sub
180 MsgBox "Error: " & Err.Description & " (" & Err & ") in procedure " & mstrModule & "." & strProcedure & " at line " & Erl
190 Resume ExitSub
If anyone can shed some light on what is happening here I would be most grateful.