Disabling a control while it has the focus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a simple quote-builer and invoicing system. When I move a project's
stage from "Quote" to "To Be Invoiced" then I want the "View Quote" button on
the previous screen to be disabled.

Access spits a Run-time error saying that 'You can't disable a control while
it has the focus.'

Is there any way to past this?

Cheers

Nick
 
I tried setting the focus to some other control first but I think it goes
back to the button I'm trying to disable

Me.Open_Inv_FixedCost_Quote_Sub.SetFocus
Form_Project_Manager.Go.Enabled = False
 
nick said:
Hi,

I have a simple quote-builer and invoicing system. When I move a
project's stage from "Quote" to "To Be Invoiced" then I want the
"View Quote" button on the previous screen to be disabled.

Access spits a Run-time error saying that 'You can't disable a
control while it has the focus.'

Is there any way to past this?

Move the focus somewhere else before disabling the control. That's the
only way. Now, since you talk about the button in question being on
"the previous screen", I'm thinking maybe this button is on a subform.
If that's the case, then even if that subform is not the active control
on the main form, as far as the *subform* is concerned that control
still has the focus. Therefore, you still have to move the focus to
another control on the subform before disabling the button. For
example,

Me!NameOfSubformControl!SomeOtherControl.SetFocus
Me!NameOfSubformControl!cmdViewQuote.Enabled = False

That's assuming the code is being executed on the main form. From some
other subform, it would be more complicated, requiring a reference chain
through the Parent form.
 
Hi, thanks for you help

Me!Date_Created.SetFocus
Forms!Project_Manager!Go.Enabled = False

The button is on the Project_Manager form. There are Open_Quote and
Open_Project buttons. Clicking on the Open_Quote button opens the quote
editor. When someone has completed the quote that person can change it's
status to "To Be Invoiced." That button click should disable the Open_Quote
button which opened the quote editor in the first place and enable the
Open_Invoice button.

Resetting the focus still gave the same error. Any ideas?
 
nick said:
Hi, thanks for you help

Me!Date_Created.SetFocus
Forms!Project_Manager!Go.Enabled = False

The button is on the Project_Manager form. There are Open_Quote and
Open_Project buttons. Clicking on the Open_Quote button opens the
quote editor. When someone has completed the quote that person can
change it's status to "To Be Invoiced." That button click should
disable the Open_Quote button which opened the quote editor in the
first place and enable the Open_Invoice button.

Resetting the focus still gave the same error. Any ideas?

I didn't understand that you are disabling a control on a completely
different form than the one that the code is running on. You need to
move the focus *on the same form that has the control you want to
disable*. So let's assume that the Open_Project button on form
Project_Manager is enabled. Then you could safely disable the button
you have variously called "Open_Quote" and "Go" like this:

With Forms!Project_Manager
!OpenProject.SetFocus
!Go.Enabled = False
End With
 
Hey thanks, that worked fine.

cheers

Dirk Goldgar said:
I didn't understand that you are disabling a control on a completely
different form than the one that the code is running on. You need to
move the focus *on the same form that has the control you want to
disable*. So let's assume that the Open_Project button on form
Project_Manager is enabled. Then you could safely disable the button
you have variously called "Open_Quote" and "Go" like this:

With Forms!Project_Manager
!OpenProject.SetFocus
!Go.Enabled = False
End With

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top