Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: Cannot disable control that has focus?

Status
Not open for further replies.

osx99

Technical User
Apr 9, 2003
250
0
0
GB
I am trying to disable a control on a subform via an event procedure from the main form in Access 2000 using:

Forms![Structure Data Input].[Costs Subform]![Feasability Contractor Works].Enabled = False

However, I get an error message 'Cannot disable a control while it has focus"

I have tried to set the focus to another field using code on the line before ...enable = false using both

DoCmd.GoToControl "GRIPStage1TotalCost"
or
Me![Costs subform].SetFocus

But I still get the error. Can anyone help?

MAny thanks,
Osx
 
Hi,

I guess that just setting the focus to the subform doesn´t work. I think you must set the focus to another control in the same sub form of the control that you are trying to disable.

Hope that helps
 
Thanks, that does work...BUT

I need to disable all the controls in the subform so need to move the focus outside otherwise I'm always left with 1 control not disabled.

Is there a workaround?

Osx
 
In a form, at least 1 control must have the focus if any controls on that form were ever given a focus. If no controls ever ahd the focus, then you don't have to be concerned.

The issue is that if a control has focus, you need to make that form active (directly or indirectly) in order to move the focus off that control. It can't be done while the form is active.

Anyhow, what you really need to do is to set at least 1 of the controls on the form to be Enabled AND set the Locked property to True. The will allow focus for the control, but the user won't be able to change the data on the control. (Sometimes they can physically type changes, but they are ignored and the field is refreshed when the focus moves off that control.)

This should solve your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top