We help IT Professionals succeed at work.

Protect a form button from repeated activation.

Hello Experts, I have a button that is starting a macro. Button works perfectly but if someone presses it a second time then the macro is running a duplicate. How could this be avoided? Thank you ahead of time.
Comment
Watch Question

Commented:
Can you disable the button and then enable the button after running the code?

Author

Commented:
This is exactly what I would like to do but I have no idea how to disable a form button.

Author

Commented:
Any chance that you could post the info here. I have tried this link you provided plus I have tried connecting to OZGRID.com for the past few weeks with only failed attempts.  I have retried just now and there is no connection to the server.

Commented:
I would like to but I don't want to post information from another site. I think that would probably violate the rules or something. I would be glad to email you a word document of the page if you would like. Is there a way that I can get your email address?

Commented:
I have attached a PDF of the thread.
http---www.ozgrid.com-forum-prin.pdf

Author

Commented:
Wow that was a great pdf link, thank you. Problem is that the buttons in question are called "form" buttons found in the forms toolbar and the buttons being address in the ozgrid links are command buttons found in the Control Toolbox. Does this mean that I will have to change all of my form buttons into command buttons?

Commented:
Can you reference the form buttons like they are referencing the command buttons?
Commented:
For example formbutton1.Enabled = True

Author

Commented:
Excellent! I am sorry to show my lack of knowledge but how do I find the name or number of a form button?
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011
Commented:
If you right click a button from the Forms toolbar (I assume you mean on a worksheet), you should see its name in the Name box just above the column A header. You can then use:
activesheet.buttons("Button 3").enabled = false

alternatively, if you are calling the same macro from several buttons, you can use:
   ActiveSheet.Shapes(Application.Caller).OLEFormat.Object.Enabled = False
which will disable whichever one you clicked on. Don't forget to re-enable it as required!

Regards,
Rory
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011

Commented:
PS You can also shorten the second one to:
ActiveSheet.Buttons(Application.Caller).Enabled = False
if you only call the macro from forms buttons, rather than any other type of control.
FWIW

Author

Commented:
Thank you both for your help. Rory Thank you for coming through and finishing off another one for me. Great answer!

Commented:
Your very welcome and I am glad that I could be of help to you.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.