473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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


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
4 2850
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: MLH | last post by:
A form named frmVehicleEntryForm has a number of textbox controls who's OnGotFocus property setting is an expression... =Change2Green() Change2Green() looks something like this... Dim MyControl...
1
by: Nigel C | last post by:
Hi, I am going round in circles... I am trying to produce a report based upon the information gathered into a temp table. Each column (stored as a text field) in the table holds weekly...
5
by: Leo J. Hart IV | last post by:
Hello, I'm hoping someone can help me out. I was wondering if the Enabled property of a CheckBox or RadioButton server control is stored in the ViewState. If not, is there some way to to add...
4
by: Phill. W | last post by:
Here's a knotty little problem. I have some nasty little controls that needs to behave in a non- windows-Standard way - don't ask why; it's a large application being converted from some older...
2
by: elaine | last post by:
Hi, I have a usercontrol which contains multiple server controls like textbox, radiobutton..., I have a public field in the usercontrol "Enabled". What i want to do is when the usercontrol's...
6
by: Brandon McCombs | last post by:
Hello, I have a Form that contains some configuration information. One of the settings is for SSL. There is a checkbox that I want to check to make 2 textboxes un-editable so that a user can...
6
by: Rob | last post by:
I would like to show dark fonts (so that the text is readable and not greyed out) in a text box, however, I do Not want the text box to be Enabled, because I do not want the text box to ever have...
3
by: nano2k | last post by:
Each form has its ActiveControl property, but no ActiveControlChanged event to signal that the active control has changed (like ParentChanged event). I tried to trick the form by declaring this...
10
by: Derek Hart | last post by:
I can set focus to my property grid by using propgrid.Focus - but how can I set the default property that is always first? Or just set focus to the default property? Can this be done?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.