How do I enable a command button depending on some condition ?

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

Guest

I have a form with 3 options each associated with a command button. I would
like all the command buttons to be disabled at start. Depending on the option
chosen by the user, the corresponding command button would get enabled and
let the user click it.
I am aware of the "On Click" property for the command button. But what
should I be doing to enable the command button.

Thanks.
 
You didn't specify what is the option, another button, data entered in a text
field.

On the After update event of the "Option" write the code

Me.OptionButton1.Enabled = (OptionValue)
Me.OptionButton2.Enabled = (OptionValue)
Me.OptionButton3.Enabled = (OptionValue)

So the option value can return true only to one of the buttons and will
return false to the other buttons

example:
OptionValue can be - Me.TextField = "Value"
So
Me.OptionButton1.Enabled = (Me.TextField = "Value")
 
Well the user gets to select from 3 different combo boxes and each combo box
has a command button that will launch a report. I see the After Update Event
for my combo box, but am not sure that I understand the optionvalue you
suggested.
example:
OptionValue can be - Me.TextField = "Value"
So
Me.OptionButton1.Enabled = (Me.TextField = "Value")

What would replace 'Textfield' in my case ? Will it be something like
Me.Commandbutton1 = "What Value do I specify to enable"..? Should the Value
be TRUE or False?

Thank you
 
If I understand you correctly, then on the after update event of each combo
you need to enable the corrensponding button (when the cursor is on the after
update event, you'll see on the right side with three dots, press on it and
select code).

Me.ButtonName.Enabled = not isnull(me.Combo1Name)
The button will be enabled when you select a value from the combo, or
disabled if you delete the value from the combo.

Do the same to the other two combo's
========================================
Another option will be , to leave the button always enable, and on the
onclick event before openning the report, to check if anything have been
selected in the combo, if not then give a message and exit, if yes, then
print the report

On the onclick event write the code

If isnull(me.Combo1Name) then
msgbox "No Selection"
exit sub
Else
Docmd.OpenReport "ReportName"
End If
 
Back
Top