• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

Error#2164 encountered while locking form. You cant disable a control while it has the focus

Hi

I want to disable all the controls on a subform when the main form loads but i receive the message that "Error#2164 encountered while locking form. You cant disable a control while it has the focus".

I have entered disable in the tag field on all the controls properties of the main form, and a standard module is used to set the enabled property of the controls to false, when the main form loads.

When i add the disable text to the tags on the subforms controls, i receive the error message above  

My main subform is called frmSIMDetails and the subform is fsubSIMDetailsNotes.

Can anyone help.?

Kind regards
DGI
0
dgi001
Asked:
dgi001
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
That error is very specific ....means what it says.  

You might try this - a trick I've been using for years - and works for many different scenarios:

Add a sliver of a text box on your form ... with border, back and fore colors matching what ever area you put in it.  Tab Stop = yes.  So, effectively, this control is .. for all practical purposes ... Invisible.

I use this all the time as a 'Focus Hold' ... when I need to disable controls. zzTxtFocusHold.  I always set focus to this control first ... then disable whatever control(s).  That way, I don't need to worry about that stupid error ... 'You can't set the focus ..."

I named it zztxtFocusHold ... so it sorts at the bottom of the controls list on the tool bar.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Also note that ... generally, a subform actually 'loads' before the Main form does ... fyi.

mx
0
 
dqmqCommented:
>I have entered disable in the tag field on all the controls properties of the main form, and a standard module is used to set the enabled property of the controls to false, when the main form loads.



mx solution is fine, but wouldn't it be simpler to disable the controls in design mode rather than tagging them in design mode to be disabled in code?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
<,I want to disable all the controls on a subform when the main form loads>>

I handle this by simply setting the sub form control's .Locked property to True.
0
 
Andrew_WebsterCommented:
Go with mx, his solution is identical to a feature I use as standard in my work.  I use the tag field to store some flags that are checked for code. The code sets focus to a tiny text box, then checks each control for the tags and disables as required.
If it finds a subform, it iterates through the subform's controls too, so the subform needs a tiny textbox too.
0
 
Nick67Commented:
Choose whichever method makes the most sense to you.
The take-away is this:
When you are going to disable a control, you have to know where the focus is, and if it is on the control, you have to move it
That's what ActiveControl and SetFocus are for :)

Private sub DisableSomething()

if Screen.ActiveControl.Name = "cmdWhatIAmDisabling" then
    me.txtSomeOtherControl.SetFocus
end if
me.cmdWhatIAmDisabling.Enabled = False

end sub


From the Access 2003 help
________________________
You can use the ActiveControl property together with the Screen object to identify or refer to the control that has the focus. Read-only Control object.

expression.ActiveControl
expression    Required. An expression that returns one of the objects in the Applies To list.

Setting
This property setting contains a reference to the Control object that has the focus at run time.

This property is available by using a macro or Visual Basic and is read-only in all views.

Remarks
You can use the ActiveControl property to refer to the control that has the focus at run time together with one of its properties or methods. The following example assigns the name of the control with the focus to the strControlName variable.

Dim ctlCurrentControl As Control
Dim strControlName As String
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name
            
If no control has the focus when you use the ActiveControl property, or if all of the active form's controls are hidden or disabled, an error occurs.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now