Full Version: You can't disable a control while it has the focus
UtterAccess Forums > Microsoft® Access > Access Forms
psalmon
It is Friday afternoon and this one is driving me nuts.
I have a control on a subform that I want to disable when the Save button is clicked on the main form.
I have set the focus to a control on the main form but I still get the You can't disable a control while it has the focus message.
There is the part of the code from the onClick event of my save button that is causing me grief
CODE
     Me.cboNCRNumber.SetFocus
    Form_sfrInterestedParties.cboInterestedParty.Enabled = False

I also have this bit of code
CODE
Me.txtFocus = Screen.ActiveControl.Name

it appears the correct control has focus.
Any idea of what I am doing wrong.
Thanks,
Pat
RuralGuy
Have you tried:
CODE
Me.cboNCRNumber.SetFocus
Me.sfrInterestedParties.FORM.cboInterestedParty.Enabled = False

...you did say the control you wanted to disable was on the SubForm, right?
Refer to Form and Subform properties and controls
psalmon
Yes my Save button is on the Main form and the control that is giving me trouble is on the subform.
I have changed the code to:
CODE
Me!sfrInterestedParties.Form!cboInterestedParty.Enabled = False

The message is the same!! You can't disable a control while it has the focus
my txtFocus control that I put on to test what has the focus with
CODE
Me.txtFocus = Screen.ActiveControl.Name

has the control that I set the focus to cboNCRNumber.
Even on Monday morning with a clearer head I can't seem to figure this one out.
Any help will be greatly appreciated
crazy.gif
RuralGuy
Any chance you have applied Office SP3? If not then don't. If you have then you will want to apply the HotFix that repairs many of the problems caused by SP3.
Description of the Access 2003 post-Service Pack 3 hotfix package: December 18, 2007
psalmon
When I look at "About Microsoft Office Access" it tells me that I am Office 2003 SP2. So I guess the SP3 problems shouldn't affect me.
I am starting to wonder if only having 1 control on the subform is causing the problem. I have thought of adding a control on the subform just to take the focus while I disable the other control. Even though it doesn't sound logical. confused.gif
Any thoughts on that?
Thanks,
Pat
psalmon
Well, I added the fake focus control to take focus for the subform. Voila!! It appears that even though I setfocus for a control on the main form, when it goes to the subform to do actions, there needs to be a control there that has focus. When I only had one control by default it had focus. Problem seems to be gone now.
RuralGuy
Excellent! Thanks for posting back with your success.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.