Disable Command Button with Macro

N

nxqviet

I tried to disable command buttons by macro. Specifically,

SetValue ... Item: [NameOfButton].[Enabled]
Expr: No
I also tried False for Expr.

This script won't work. Is there a way of disabling command button
using macro? I guess I could try to do away with all macros and replace
them with code. But I have so many macro, it would be better to add 1
more line to the macros than to rewrite everything.


Thanks,



V_
 
N

nxqviet

To be more specific.

I have a button (ButtonA) that will run a macro when clicked. In each
of these macro, I have conditions that will stop the macro if some
fields in the form are incomplete. If all fields are filled out
correctly, the macro will continue and will eventually disable the
button (ButtonA) so that users can not click it twice.

All of these actions in the macro can be written in code, but I have so
many macros and buttons that are liked to these macros, I want to be
able to add one more line to each macro rather than rewrite all of them
in code.

Thanks,
 
G

gumby

Create a Modules

Function HideAccessCommandButton()
Forms.Item("frmTest").Controls.Item("Command14"). _
Transparent = True ' False to unhide
End Function


' frmTest = Form Name
' Command14 = Command Button you want to hide.


Add 'Run Code' Action to your Macro

In the function name: call your Function like this:

HideAccessCommandButton ()

If you change the function name, just change the function in your
macro.

To unhide I would create a seperate Macro.
 
G

gumby

It's probably not working because you cannot change a control that has
focus. You may want to base the

[ButtonA].[Enabled]
False

on whether or not a field [field] Is Not Null Null as a condition. When
the form loads or probably afterupdate might work better, it will check
to see whether all fields you list Is Not Null. Once all fields are Is
Not Null then the ButtonA would be Enabled=False.

One thing to point out is once you diable a button is is disabled. You
have to Enable it by a macro to get it back. of Enabled=True.

VBA is the way to go in this case. But like you said you were not
wanting to go down that path. But if you do you could create a Function
and then add one line to your macro 'RunCode' and call that function.
 
G

gumby

It's probably not working because you cannot change a control that has
focus. You may want to base the

[ButtonA].[Enabled]
False


on whether or not a field [field] Is Not Null as a condition. When
the form loads or probably afterupdate might work better, it will check

to see whether all fields you list Is Not Null. Once all fields are Is
Not Null then the ButtonA would be Enabled=False.


One thing to point out is once you diable a button it is disabled. You
have to Enable it by a macro to get it back. so Enabled=True.


VBA is the way to go in this case. But like you said you were not
wanting to go down that path. But if you do you could create a Function

and then add one line to your macro 'RunCode' and call that function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top