Re: ActiveControl in Form View



Leif wrote:

>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.

--
Marsh
MVP [MS Access]
.



Relevant Pages

  • Re: Does a textbox have to have a name reference, or can I use a w
    ... I misintepreted what you meant by 'ActiveControl'; ... no, in the code i posted, ActiveControl refers to the control *on the ... subform* that had the focus before the command button on the mainform ...
    (microsoft.public.access.formscoding)
  • Re: How to refer to "current control" in event handler
    ... I won't be using ActiveControl, then, based on your advice. ... (I was using SendKeys to preset the options in a Find ... > So, yes, I hard-code the name of the control. ... > Public Function MakeHighlightAs Boolean ...
    (microsoft.public.access.forms)
  • Re: .NET / C# equivalent of GetFocus()?
    ... Control control = Control.FromHandle; ... instead the activecontrol of the form/usercontrol is ... > activecontrol of form can be things like the tab control, ... > directly on the form or your usercontrol. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: .NET / C# equivalent of GetFocus()?
    ... The activecontrol does not return an item within a containercontrol ... control within it that is active or the contained container control if that ... of form can be things like the tab control, ... usercontrol is a single unit and the containing object should not be dealing ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: ActiveControl in Form View
    ... not the name of a control on the same form. ... However, in datasheet view if the user checks on the field to be disabled, ... My question is why does Access think the window is not active? ... Is ActiveControl not available in the ...
    (microsoft.public.access.formscoding)