Solved

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

Posted on 2013-05-26
10
2,868 Views
Last Modified: 2013-06-05
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.Figure 1.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.Figure 2.Keyed in an ‘r’.Figure 3.Keyed in an ‘e’Figure 4.Keyed in a backspace, got the error.Figure 5. 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
0
Comment
Question by:shambalad
  • 6
  • 3
10 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
Comment Utility
If I key in ANY invalid combination (like "zz", for example) I get the error.

But that doesn't explain why you'd get an error on the line you specified. You should be able to SetFocus to the control regardless of whether the items keyed into the combo are legit or not. I could understand if the code at lines 110 or 120 would fail - those get down to the lower levels of the control, and used incorrectly they could certainly cause issues - but a simple SetFocus should not cause this.

I have no idea why this would occur, but it does so everytime I enter an invalid key combination.

Given that this is a proof of concept  sort of issue, I'd say that you have run into a wall - or at the very least, a wall I'd not be willing to try and scale :)
0
 
LVL 7

Author Comment

by:shambalad
Comment Utility
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.
0
 
LVL 7

Author Comment

by:shambalad
Comment Utility
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.
0
 
LVL 84
Comment Utility
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 ...
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 7

Author Comment

by:shambalad
Comment Utility
That's what appears to be happening. I working on work-around right now.
0
 
LVL 7

Accepted Solution

by:
shambalad earned 0 total points
Comment Utility
It kind of makes sense that Access won't let the focus shift away from the combo box when it is bound, has an invalid value and doesn't allow 'not in list' entries. In data entry, if you try to tab out of a combo box with those properties and an invalid value, Access won't let you move either.
Anyway, I think I've got this behaving the way it should. I actually only need to set the focus to the list box to get the control handle, so I'm saving the handle from the 1st pass for subsequent calls. Getting the text in the combo box to display what I wanted it to was another issue, but I think I've got that too. I've attached the updated db. I'm going to take a break from it for the moment and see if I still like it tomorrow.
Thanks,
Todd
Sync-Controls-Demo.accdb
0
 
LVL 7

Author Comment

by:shambalad
Comment Utility
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
0
 
LVL 84
Comment Utility
That sounds reasonable ...
0
 
LVL 7

Author Closing Comment

by:shambalad
Comment Utility
Stated my reasoning in previous post. Thanks to all on this forum for your help.
Todd
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now