ActiveControl in Form View

G

Guest

I have a form with a checkbox control and a text field. If the checkbox
control is not checked then I want the text field disabled (enabled = false).

This is being done in the form_current event. It works fine in form view,
since in moving between records in form view the focus is always set to the
first field when the record is changed.

However, in datasheet view if the user checks on the field to be disabled,
on a differnt record, then I get the error message that a field that has
focus cannot be disabled (which makes sense).

To overcome this problem I tried adding code to my form_current event to
detect if the current control is the one I'm trying to disable. This works
fine in datasheet sheet, however in form view I get the message:

Error 2474

"The expression you entered requires the control to be in the active window"

The offending code is:

If Screen.ActiveControl.Name = "DDWO" Then PMTNumber.SetFocus '
Change focus if necessary


My question is why does Access think the window is not active? It appears
to be active to me, and the code presents no problems in datasheet view, only
form view when I change the record. Is ActiveControl not available in the
form_current event? Is there a work around?

Thanks.
 
M

Marshall Barton

Leif said:
I have a form with a checkbox control and a text field. If the checkbox
control is not checked then I want the text field disabled (enabled = false).

This is being done in the form_current event. It works fine in form view,
since in moving between records in form view the focus is always set to the
first field when the record is changed.

However, in datasheet view if the user checks on the field to be disabled,
on a differnt record, then I get the error message that a field that has
focus cannot be disabled (which makes sense).

To overcome this problem I tried adding code to my form_current event to
detect if the current control is the one I'm trying to disable. This works
fine in datasheet sheet, however in form view I get the message:

Error 2474

"The expression you entered requires the control to be in the active window"

The offending code is:

If Screen.ActiveControl.Name = "DDWO" Then PMTNumber.SetFocus '
Change focus if necessary


My question is why does Access think the window is not active? It appears
to be active to me, and the code presents no problems in datasheet view, only
form view when I change the record. Is ActiveControl not available in the
form_current event?

The Screen object refers to the entire Access window where
all kinds of things, including any open form may be
"active". Try using Me.ActiveControl.Name instead.
 
G

Guest

After changing to Me.ActiveControl.Name I'm still getting the same error
message.

Regards,
Leif
 
M

Marshall Barton

The only thing that comes to mind is that maybe PMTNumber is
not the name of a control on the same form. Or maybe your
form is more complicated than you've described.
 

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