Disable/Enabling a button

E

essseeproductions

Hi i have a macro which is executed when i click the button. I want to
add two options to this though.

Before the macro is executed i would like a warning of my desired text
to be displayed offering the user to cancel.
I would also like to disable the macro before a certain date as it
cannot be run until after a certain month.

Are the two options possible? Many thanks in advance.
 
S

storrboy

Hi i have a macro which is executed when i click the button. I want to
add two options to this though.

Before the macro is executed i would like a warning of my desired text
to be displayed offering the user to cancel.
I would also like to disable the macro before a certain date as it
cannot be run until after a certain month.

Are the two options possible? Many thanks in advance.


You can only affect control properties in VBA. You can add conditions
to macros, but they are not protected from other users prying eyes.

To display a message that won't give a 'macro cancelled' message, add
the following to the buttons click event.

Dim lvRet As Long
lvRet = MsgBox("[Enter prompt here]", vbOkCancel, "[Enter Messagebox
Title]"
If lvRet = vbOK Then DoCmd.RunMacro "[Name of Macro]"

To disable the button, you'll have to decide when that needs to occur.
Probably when the form opens? If so add this to the form's Open event
(or other event of yuor choosing)

If Date() < CDate("[Enter Date String]") Then Me![ButtonName].Enabled
= False.

Be sure that the button being disabled does not have the focus when
this code is run.
 
Top