Trying to run Module from a button (1 Viewer)

andrewkoemm

New member
Local time
Today, 15:45
Joined
May 7, 2015
Messages
8
I have created a module that runs a print screen command. The module runs great when I run it from the VBA window. But I do not know how to run the command from a button so that it can take a screen shot of the form.

Here is my code below:
PS.PNG
 

maw230

somewhat competent
Local time
Today, 14:45
Joined
Dec 9, 2009
Messages
522
I have created a module that runs a print screen command. The module runs great when I run it from the VBA window. But I do not know how to run the command from a button so that it can take a screen shot of the form.

Here is my code below:
View attachment 58380

If you go to the properties of the button on the form you can locate the On Click Event property. From there you can set the code to run when the button is clicked.

Not sure if it can reference the Private sub, so if you have strange errors that could be it.

Wish I had more for you, but I wanted to at least give you something until someone else can chime in. Good luck.
 

andrewkoemm

New member
Local time
Today, 15:45
Joined
May 7, 2015
Messages
8
Sorry that did not work. Before i posted this thread i spend an hour searching through Google and trying different approaches, with no progress.
 

maw230

somewhat competent
Local time
Today, 14:45
Joined
Dec 9, 2009
Messages
522
Create a Public function that does something simple and see if you can run it using the On Click Event of the button. If so, then it's possible that your Private function can't be called or it could be something else. Try moving your code into a Public function if possible.
 

andrewkoemm

New member
Local time
Today, 15:45
Joined
May 7, 2015
Messages
8
Does it matter if its a sub or function? I have it as a sub.

Is this what you are tell me to do:

Call.PNG
 

maw230

somewhat competent
Local time
Today, 14:45
Joined
Dec 9, 2009
Messages
522
Does it matter if its a sub or function? I have it as a sub.

Is this what you are tell me to do:

View attachment 58384

Sorry about my wording, just a Public sub is what I meant.

Instead of using the "Expression Builder" click on "Code Builder" when selecting the on click event property. From there type something simple like
Code:
MsgBox "It works!?"
in the sub and see what happens when you click your button.
 

andrewkoemm

New member
Local time
Today, 15:45
Joined
May 7, 2015
Messages
8
Ok that simple code worked. So what am I doing wrong when I am trying to implement my screen shot code.
 

maw230

somewhat competent
Local time
Today, 14:45
Joined
Dec 9, 2009
Messages
522
Did you try to copy and paste the AltPrintScreen sub into the On Click sub you just created? Replace the "MsgBox" code with that and see if it works or returns errors.
 

maw230

somewhat competent
Local time
Today, 14:45
Joined
Dec 9, 2009
Messages
522
Keep your original code, and ONLY place the AltPrintScreen portion in the On Click sub.

Beyond that, I'm not sure how much help I can be, but I'm sure someone else on here can.
 

andrewkoemm

New member
Local time
Today, 15:45
Joined
May 7, 2015
Messages
8
Sorry no progress. :banghead:

Hopefully someone else will be able to assist.
Thanks for the help.
 

maw230

somewhat competent
Local time
Today, 14:45
Joined
Dec 9, 2009
Messages
522
Sorry no progress. :banghead:

Hopefully someone else will be able to assist.
Thanks for the help.

You're welcome. If it's urgent I would recommend to create a new thread with a link to this one and explain it's urgency. This thread has a possibility of being buried.
 

Cronk

Registered User.
Local time
Tomorrow, 05:45
Joined
Jul 4, 2013
Messages
2,774
You cannot embed subs. You can call other subs but the code cannot be contained in the original Sub.
 

Users who are viewing this thread

Top Bottom