|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Macros - New to access; runmacro action not working
I created a simple macro to type message using Msgbox "test" and tried to run it using runmacro. But, nothing happens. No errors or messages. Please help. Thanks.
|
|
#2
|
|||
|
|||
|
Depending on the version of access you're running you will have to enable macros. For access 2003 you would do this:
TOOLS>MACROS>SECURITY You are probably set to a medium or high security which prevents almost everything from running. For Access 2007 it's slightly different and I can't remember it off the top of my head.
__________________
---------------- If we've helped you and you have solved your problem please post that it's been resolved so we know! The suspense kills me! |
|
#3
|
|||
|
|||
|
Thank you for the suggestion. No, that wasn't it. I already had the security level in Access 2007 set to enable all Macros. Any other ideas?
|
|
#4
|
|||
|
|||
|
Did you save the macro before trying to run it. Usually access forces you to save before you can run but that may be turned off in your case.
Your macro has 1 line only that says MsgBox in the action arguments (lower left of the screen in anything below access 2007) there are four lines. The first one says test in it? |
|
#5
|
|||
|
|||
|
This is how I created and stored my macro (similar to Excel which I am more familiar with):
On the Form View, I hit Alt+F11 and typed the following code: Option Compare Database Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''' Private Sub cmdOpenExcelFile() MsgBox "Test" End Sub (As you may have guessed from the name of the macro the purpose of the macro eventually is to open an excel file while in the Access program. For the present, I just wanted it to type a message through a MsgBox command.) Then, I wanted to activate this macro using a command button. So, I created a button and tried to run the macro by clicking on properties and event. But nothing happens (after saving, properly exiting the design mode and entering the form view). Also, tried to enter the Macro mode directly by clicking on the Create>>Macro>>Action (Runmacro)>>Argument buttons, and again nothing happens. Incidentally, by the same approach if I picked message box action instead of the runmacro, the message box works properly. Hope this clarifies some. Thanks for your help. |
|
#6
|
|||
|
|||
|
That's not a macro, that's VB script.
What you want to do is create your button FIRST then in your form design view click on the button, bring up the properties and in the ON CLICK event you want to put in your msgbox "test" the code surrounding it will be something like Private Sub cmdOpenExcelFile_Click() MsgBox "Test" End Sub |
|
#7
|
|||
|
|||
|
Thank you for your prompt response. I greatly appreciate it. The question I have is where is this code located (e.g., Alt F11 does not show this code in Form_Form1) so that I can replace the MsgBox statement with a set of statements to perform other tasks (namely, as I indicated before, to open an excel file).
Thanks as always. |
|
#8
|
|||
|
|||
|
Create a form
put a button on the form called Cmd_001 right click on the button Cmd_001 and click PROPERTIES Scroll down to the ON CLICK property Click on the row containing the label ON CLICK Click on the three button labeled ... Select CODE BUILDER The code builder will supply the sub opening and closing Code:
Private Sub Cmd_001_Click() End Sub Type MSGBOX "TEST" between the opening and ending of the command Code:
Private Sub Cmd_001_Click() msgbox "TEST" End Sub close the VBScript window open the form in form view click on the button the message box should pop up. not sure how much clearer it can be. If you then want to modify what the button does you just go back to the design view go to the properties of the button to the ON CLICK event and modify the code. |
|
#9
|
||||
|
||||
|
~rpeare has given you step-by-step instructions for creating a VBA Event Procedure, which as he said is completely different from a Macro. I just thought I would add a little background for you. What you were attempting to do (and calling a Macro, which again is something entirely different) was a procedure in a Module, which you can reach by opening the Modules tab in the Database Window. But those are only used for procedures and functions which are NOT related to actions based on some event on a Form. Such actions as clicking on a button are done either with Macros (which most of us never use because of their limited functionality) or Event Procedures, which is what ~rpeare showed you how to do. Event Procedures (sometimes called Class Functions) are stored as part of the Form they are called from, and can be reached through the properties sheet of the component or part of the Form that calls them. You can also open all the VBA code for a Form or Report by pressing Alt+F11.
__________________
Experience is the thing you have left when everything else is gone. |
|
#10
|
|||
|
|||
|
It works!! I can't thank you enough.
By way of feedback, 1. I need to educate myself on the terminology better: Macro vs. VB script 2. I had the VB script prepared first and then tried to assign that to a button I created; the system is not meant to do that. I wonder why. 3. I also did not go into Code Builder (saw only Macro Builder). Thanks again. |
|
#11
|
|||
|
|||
|
Thanks for the input. I will work on the semantics. You had a lot of topics in your message. I will try to learn about them one by one.
|
|
#12
|
||||
|
||||
|
Not meaning to pile on, but there's an important difference between VB (Visual Basic) scripts and VBA (Visual Basic for Applications). A lot of the syntax is the same, but VBA is very specific to Microsoft Office Applications, while VB is a generalized scripting language.
Yes, it will really improve your ability to get help in forums and elsewhere if you have the terminology correct. This is a terribly detailed and finicky business, and accurate understanding is possible only when everyone understands what the others are referring to at every point. You'll learn, with more experience. |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > Macros - New to access; runmacro action not working |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|