?
Solved

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

Posted on 2011-05-11
6
Medium Priority
?
498 Views
Last Modified: 2012-05-11
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
Comment
Question by:dgi001
6 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 35739469
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
 
LVL 75
ID: 35739494
Also note that ... generally, a subform actually 'loads' before the Main form does ... fyi.

mx
0
 
LVL 42

Expert Comment

by:dqmq
ID: 35739828
>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21
ID: 35739846
<,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
 
LVL 8

Expert Comment

by:Andrew_Webster
ID: 35739880
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
 
LVL 26

Expert Comment

by:Nick67
ID: 35740451
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question