By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,218 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,218 IT Pros & Developers. It's quick & easy.

How to set Enabled property - wont allow if control has focus

P: n/a

I have 2 command buttons on a form. I want the first one to be enabled and
the second one to be disabled when the form is opened. That works fine.
Then, after the user has pressed the first button, I want them reversed -
button #2 is enabled and #1 is disabled.

But I keep getting this error message: "You can't disable a control while
it has the focus".

The code is basically this:
Upon open
btn1.Enabled = True
btn2.Enabled = False

After btn1 is pressed, do some stuff and then:
btn1.Enabled = False
btn2.Enabled = True

Do I need to move the last bit of code out of that sub or is there something
else that I need to do?


Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try:
btn2.SetFocus
btn1.Enabled = False
btn2.Enabled = True

Stewart
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:K%Nxc.1919$eu.1185@attbi_s02...

I have 2 command buttons on a form. I want the first one to be enabled and the second one to be disabled when the form is opened. That works fine.
Then, after the user has pressed the first button, I want them reversed -
button #2 is enabled and #1 is disabled.

But I keep getting this error message: "You can't disable a control while
it has the focus".

The code is basically this:
Upon open
btn1.Enabled = True
btn2.Enabled = False

After btn1 is pressed, do some stuff and then:
btn1.Enabled = False
btn2.Enabled = True

Do I need to move the last bit of code out of that sub or is there something else that I need to do?

Nov 13 '05 #2

P: n/a
I actually had tried that already and it did not work. I found in the
archives a reference to this problem. The solution that was suggested was
the one I used - a dummy control is put on the form (in my case, a
transparent button hidded behind an existing button) and that gets the focus
so that the code does not blow up. Frankly, such a workaround seems stupid
to me. If, indeed, this is the only way to get the job done, then Microsoft
has committed a major screwup in my mind. While it may be that a control
that has focus cannot be disabled, it should be able to pass the focus
elsewhere and *not* to a dummy control hidden on a form!
Anyhow, this was the solution:
btnDummy.SetFocus
btn1.Enabled = False
btn2.Enabled = True

"Stewart Allen" <sa****@NOT.wave.THIS.co.nz> wrote in message
news:ca**********@news.wave.co.nz...
Try:
btn2.SetFocus
btn1.Enabled = False
btn2.Enabled = True

Stewart
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:K%Nxc.1919$eu.1185@attbi_s02...

I have 2 command buttons on a form. I want the first one to be enabled

and
the second one to be disabled when the form is opened. That works fine.
Then, after the user has pressed the first button, I want them reversed - button #2 is enabled and #1 is disabled.

But I keep getting this error message: "You can't disable a control while it has the focus".

The code is basically this:
Upon open
btn1.Enabled = True
btn2.Enabled = False

After btn1 is pressed, do some stuff and then:
btn1.Enabled = False
btn2.Enabled = True

Do I need to move the last bit of code out of that sub or is there

something
else that I need to do?


Nov 13 '05 #3

P: n/a
Try
btn2.Enabled = True
btn2.SetFocus
btn1.Enabled = False

This enables the second button first then applies the focus to the second
button and disables the first button. There should be no need to use a dummy
control

Stewart
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:0C7yc.6666$eu.3753@attbi_s02...
I actually had tried that already and it did not work. I found in the
archives a reference to this problem. The solution that was suggested was
the one I used - a dummy control is put on the form (in my case, a
transparent button hidded behind an existing button) and that gets the focus so that the code does not blow up. Frankly, such a workaround seems stupid to me. If, indeed, this is the only way to get the job done, then Microsoft has committed a major screwup in my mind. While it may be that a control
that has focus cannot be disabled, it should be able to pass the focus
elsewhere and *not* to a dummy control hidden on a form!
Anyhow, this was the solution:
btnDummy.SetFocus
btn1.Enabled = False
btn2.Enabled = True

"Stewart Allen" <sa****@NOT.wave.THIS.co.nz> wrote in message
news:ca**********@news.wave.co.nz...
Try:
btn2.SetFocus
btn1.Enabled = False
btn2.Enabled = True

Stewart
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:K%Nxc.1919$eu.1185@attbi_s02...

I have 2 command buttons on a form. I want the first one to be enabled
and
the second one to be disabled when the form is opened. That works
fine. Then, after the user has pressed the first button, I want them

reversed - button #2 is enabled and #1 is disabled.

But I keep getting this error message: "You can't disable a control while it has the focus".

The code is basically this:
Upon open
btn1.Enabled = True
btn2.Enabled = False

After btn1 is pressed, do some stuff and then:
btn1.Enabled = False
btn2.Enabled = True

Do I need to move the last bit of code out of that sub or is there

something
else that I need to do?



Nov 13 '05 #4

P: n/a
Thanks, that worked!

"Stewart Allen" <sa****@NOT.wave.THIS.co.nz> wrote in message
news:ca**********@news.wave.co.nz...
Try
btn2.Enabled = True
btn2.SetFocus
btn1.Enabled = False

This enables the second button first then applies the focus to the second
button and disables the first button. There should be no need to use a dummy control

Stewart
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:0C7yc.6666$eu.3753@attbi_s02...
I actually had tried that already and it did not work. I found in the
archives a reference to this problem. The solution that was suggested was
the one I used - a dummy control is put on the form (in my case, a
transparent button hidded behind an existing button) and that gets the

focus
so that the code does not blow up. Frankly, such a workaround seems

stupid
to me. If, indeed, this is the only way to get the job done, then

Microsoft
has committed a major screwup in my mind. While it may be that a control that has focus cannot be disabled, it should be able to pass the focus
elsewhere and *not* to a dummy control hidden on a form!
Anyhow, this was the solution:
btnDummy.SetFocus
btn1.Enabled = False
btn2.Enabled = True

"Stewart Allen" <sa****@NOT.wave.THIS.co.nz> wrote in message
news:ca**********@news.wave.co.nz...
Try:
btn2.SetFocus
btn1.Enabled = False
btn2.Enabled = True

Stewart
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:K%Nxc.1919$eu.1185@attbi_s02...
>
> I have 2 command buttons on a form. I want the first one to be

enabled and
> the second one to be disabled when the form is opened. That works fine. > Then, after the user has pressed the first button, I want them

reversed -
> button #2 is enabled and #1 is disabled.
>
> But I keep getting this error message: "You can't disable a control

while
> it has the focus".
>
> The code is basically this:
> Upon open
> btn1.Enabled = True
> btn2.Enabled = False
>
> After btn1 is pressed, do some stuff and then:
> btn1.Enabled = False
> btn2.Enabled = True
>
> Do I need to move the last bit of code out of that sub or is there
something
> else that I need to do?
>
>
>
>



Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.