Solved

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

Posted on 2013-05-26
10
3,005 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
ID: 39198536
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
ID: 39207403
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
ID: 39207426
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
ID: 39207560
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
ID: 39207612
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 7

Author Comment

by:shambalad
ID: 39207665
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
ID: 39208777
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
ID: 39211761
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
ID: 39211769
That sounds reasonable ...
0
 
LVL 7

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

939 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

10 Experts available now in Live!

Get 1:1 Help Now