Moving focus

Dembrey

Registered User.
Local time
Today, 05:06
Joined
Mar 6, 2002
Messages
65
Hi all,

Been stuck on this quite a while, here's the problem.

On each of my forms I have a Locked/Edit button pair to control the 'edit' status of the form's controls (and any subforms controls).

These buttons execute some generic code (used by all forms) which uses a For Each...loop to lock/unlock each (textbox, combobox, etc) control as necessary.

However for command buttons I have to use the Enabled/Disabled property. Unfortunately you can't disable a control that has focus and sometimes one of these buttons has the focus so the VBA code bombs out at this point.

So my question is twofold: Can I test a control for focus and then move the focus "somewhere else" in case of a positive result. The "Somewhere else" being any textbox, combobox, etc. on the form/subform - I can't explicity give a control name since the function is generic and used by many forms.

Thanks for any help.
 
You can return the name of the control that has the focus with:

Screen.ActiveControl.Name

So to test whether a control you are interested in has the focus and if so, move the focus elsewhere:

if Screen.ActiveControl.Name="MyTextBox" then
DoCmd.GoToControl "AnotherTextBox"
EndIf


Hope that helps.

Andy
 
Andy,

Thanks.

I'm having some trouble with syntax since the control is sometimes in a form, sometimes in a subform on a form, ...etc.

Got some more things to try before I cry help though.

Thanks for the info.
 

Users who are viewing this thread

Back
Top Bottom