Subform focus problem

G

Guest

I have a main form with one subform. All field controls on the main form and
the subform are disabled initially. The main form has several buttons, one
of which has code enabling certain subform fields for editing. When the user
is done editing subform fields they must click on another main form button
which disables the subform controls just edited. My problem is at this point.

I believe that clicking on a button would normally change the focus to that
button. However, if the focus is on a subform control and the user clicks on
a main form button, then they get a message saying "can't disable a control
that has the focus". So, Access still thinks the subform has the focus, even
though the user has clicked on a main form button.

How do I work around this little problem? I've tried several things to no
avail. It seems that once the subform has the focus, I can't get the focus
to go back to the main form so that I can disable the subform controls.
 
K

Ken Snell [MVP]

You're being "tripped up" by the fact that there is the "current focus"
(which you get when you click on the command button) and the "focus for the
form or subform", which is still maintained even when you move the current
focus away from that form or subform. You will need to move the focus in the
subform to a different control before you disable that control.
 
G

Guest

Thanks, Ken. You can tell I haven't worked much with subforms. I didn't
realize that there is a form focus and a current focus.

I don't know what to do about this yet because I wanted all controls to be
disabled as the user moved out of the subform. Obviously hidden or already
disabled controls can't receive the focus, so that doesn't help. Is there
any way you can think of to accomplish this?

ctdak
 
K

Ken Snell [MVP]

Add a very tiny textbox (height = 0 and width = 0) to the subform. Set the
focus on that textbox and don't disable it when you disable the others.

Another method would be to disable the entire subform when its OnExit event
occurs, but then you'll need to remember to reenable it via code if you want
the user to be able to go back and make any changes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top