We help IT Professionals succeed at work.

how to set command buttons enable property to false

davetough
davetough asked
on
have attached db:
open db and a form opens
2 buttons [IN] and [OUT]-( after you click either one - db closes)
Is there a way to set cmd button enabled property to false after one is clicked?
example: User clicks [IN] - database closes- when opens back up - The IN button enabled property is set to false? the same with OUT button ( and IN button enabled property goes back to true ?
thank you
InOut-Time.accdb
Comment
Watch Question

Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
yes,

You can set the enabled property of a command button at any point, but you cannot set it to False unless the control does not have the focus.

I generally set the default for my command buttons enabled property to False, then enable the button as conditions change on a form which would allow the user to click on them.

in a form, the syntax would be:

me.cmd_DoSomething.Enabled = True

if you try to set the property to False while the control has the focus, it will raise an error.  I generally add code to my error handlers which will handle this error by setting the focus to another control (one that I know is enabled) and then use the Resume command so that the error handler shifts control back to the line that sets the property to False.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007
Commented:
Enter the 'Focus Hold' trick:

You might try this - a trick I've been using for years - and works for many different scenarios:

Add a sliver of a text box on your form ... with border, back and fore colors matching what ever area you put in it.  Tab Stop = yes.  So, effectively, this control is .. for all practical purposes ... Invisible.

I use this all the time as a 'Focus Hold' ... when I need to disable controls. zzTxtFocusHold.  I always set focus to this control first ... then disable whatever control(s).  That way, I don't need to worry about that stupid error ... 'You can't set the focus ..."

I named it zztxtFocusHold ... so it sorts at the bottom of the controls list on the tool bar.

mx