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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot disable an enabled control

Status
Not open for further replies.

Spruce4U

Technical User
Feb 1, 2006
23
CA
I have a VBA command that disables a button when a criteria is met.

When it reaches the line:
Forms!PCR_a_reprendre_options!BoutonReprendre.Enabled = False

VBA tells this:
Error 2164
Cannot disable an enabled control


Has anyone got a clue about this?

Thanks
 
Has this button got focus when you try to disable it? If so, try moving the focus first.
 
Actually I solved it by manually setting it to 'disabled' in the properties of that button control in form design view.

From then on, for no apparent reason, the VBA code had no problem enabling/disabling the control.

Weird stuff...
 
How are ya Spruce4U . . .

Your last post doesn't jive.
MicrosoftError2164 said:
[blue]You can't disable a control while it has the focus[/blue]
This saids the code you've posted in running in the very button you wish to disable! . . . [blue]It all fits like a glove![/blue]

You say you disabled the button in [blue]design view![/blue] . . . [purple]So how is it your able to click the button in the first place![/purple]

[blue]Forgive me . . . but either there's something your not telling us or you have a serious problem![/blue] . . . or, this is [purple]HomeWork![/purple]

Not mentioning the fact you ignored my colleague [blue]Remou's[/blue] question . . . . [blue]it does appear this is HomeWork!. . .[/blue]

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Actually it's perfectly normal to have a button disable itself in it's own click event. Think of a "Save Changes" or "Apply" button. Once the data's been saved, it makes sense to disable the button, until some new change causes it to be enabled again.

As Remou said, setting focus on some other control is the solution.
Code:
Private Sub cmdDisable_Click()
    Text1.SetFocus
    cmdDisable.Enabled = False
End Sub
 
JoeAtWork . . .

Yes I realize that but [blue]Spruce4U[/blue] has it disabled in design view! . . .

Ohhhh well . . . at least [blue]Spruce4U[/blue] has solved their problem . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top