Access 2002 ADP: Form, subform focus problem

D

dmcheng1

I have a form / subform focus problem that's driving me crazy.

Here's my setup: I have an Access 2002 ADP connecting to a SQL 2000
db. On the data entry form (single record), I do not use the Access
navigation buttons. Instead, all the data fields are Disabled by
default, and I built Add and Edit buttons along with Previous and Next
arrow buttons. The user can click through and view the records, but
must click the Edit button to edit the data fields. If they decide to
cancel the edit, they click the Cancel button that I provide.

I have used the Tag property to tag all the data fields as "Data." I
have a routine that loops through form's controls and enables/disables
the tagged controls. So, when you click the Edit button, the routine
enables the data fields. Clicking on the Cancel button disables the
fields.

So far so good. The problem occurs with a subform that I have on the
main form. If the user clicks Edit, then clicks into the subform, and
then decides to click the Cancel button on the main form, I get an
error "Field cannot be disabled while it has the focus" and the field
that is causing the error is on the subform.

I have tried everything I can think of to move the focus back to the
main form when the Cancel button is clicked:

* In the subform's OnExit, setting the focus to the main form and then
to an enabled control on the main form.
* On the main form itself, I select the subform's control, and in the
OnExit, setting the focus to the main form and then to an enabled
control on the main form.
* In the Cancel's button's OnClick, setting the focus to an enabled
control on the main form.

None of these work. Is there something else I can try?

Thanks
David
 
S

sebt

Hi David

I remember running in this one. I think the answer is that Access
holds a record of which control on the subform has the "focus", even
when in fact the real (visible) focus is on the main form. So every
open form (including subforms) has a control that currently "has the
focus" - meaning, more accurately "would have the focus if that form
had focus".

The solution, if I remember right, is to have a non-disableable (i.e.
without "Data" in the tag) control on the subform, and set focus to
that in the button's Click event. You can also use the CurrentControl
property of either form to work out which control currently has focus.

let me know if this works!

cheers


Seb
 

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