Subform List setfocus failing when record selected

krausr79

Registered User.
Local time
Today, 13:01
Joined
Oct 5, 2012
Messages
26
I have a form with a subform. The subform is a datasheet for my main form (like a split form, but as a subform to avoid naughty split form problems). The subform has a Form_Current which I use to clear and repopulate main form fields when different records are selected. One of the main form fields cleared is a listbox, which I set to selection -1 to clear. I use this code to do so:

Code:
Forms("frmEDFP").SetFocus
Forms("frmEDFP").Controls("lstReason").SetFocus
Forms("frmEDFP").Controls("lstReason").ListIndex = -1

The above setup works like I want except when an entire line is selected on the subform. If I click from field to field in different lines on the subform, things are fine. If I click between two lines or off to the left so an entire row is selected, then the next record switch will give the error:

Error 2110: Access can't move focus to the control lstReason.

lstReason is neither hidden nor disabled. What's going wrong??

Update: My original problem is unsolved but circumvented. The setfocus was not specific to the listbox, once it decided it couldn't focus, no control on the main form could have focus set to it. The code Forms("frmEDFP").SetFocus could be removed without any effect, so I don't think the main form was ever actually being selected. Probably the actions above would select the subform so that the controls on the main form became unreachable.

All I really wanted to do was clear the listboxes, though. I found a different no-need-to-focus method of doing that from the main form's code:

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acListBox Then ctl.Value = Null
Next

It would still be good to know how to truly remove focus from the subform/focus the main form so the original code would work.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom