# Calling a VBA access macro from an Access VBA procedure



## PincivMa (Mar 14, 2004)

Hi all

I know how to call a macro in Excel. The code is as follows:

Application.run "MacroName"

How do I call another VBA procedure or an Access Macro or an Access DoCmd procedure in an Access VBA procedure?? Does anyone out there know how??

Mario


----------



## Simon71 (Feb 9, 2005)

Mario,

I would call another VBA proceedure from within a proceedure as follows:

call proceedureName()

Hope this helps,

Simon


----------



## OBP (Mar 8, 2005)

Mario, the docmd is not a procedure, it is a VB command and you can include it on any VB line of code.
If you want to "call" a procedure that is in the same form module as the "calling" procedure you do not need to use the word call just the name of the procedure, so in simon's case just
proceedureName
If you need to pass a value to the procedure then you would use 
proceedureName(variable) where the called procedure specify what the variable name is that you use for "variable".


----------



## PincivMa (Mar 14, 2004)

Hi OBP and Simon71

Your suggestions do not work. I'm still getting an error.

I'm not so sure I explained myself properly. I have created a BVA procedure in a Module called Module1 (see code below). This procedure is then a Public one. In this procedure, I want to call another procedure that is a private one. This procedure is behind the Form I call Form1. The procedure in Form1 is called Private Sub Command3_Click().

Here is the code. 

Public Sub MySub()
Question = "Do you want to continue"
Answer = MsgBox(Question, vbYesNo, "Question")
If Answer = vbNo Then
Exit Sub
ElseIf Answer = vbYes Then
Call Command3_Click()
End If
End Sub

When I run the above procedure called MySub() I get an error on the line that starts with Call. 

Mario


----------



## cristobal03 (Aug 5, 2005)

You cannot call a private routine from outside its scope--in this case, its module. You will have to declare that click routine *Public* instead of *Private* if you need to use it outside its class module.

chris.


----------



## PincivMa (Mar 14, 2004)

OK Chris

I'll set both VBA procedures to public and see what happens. I'll keep you posted.

Mario


----------



## cristobal03 (Aug 5, 2005)

Also (sorry I forgot to mention this), you _may_ need a pointer to the module. I don't know if that's the case or not. I don't really know the syntax either, though it may look something like this:


```
Call Form_frmSomeForm.Command3_Click()
```
That's kind of a guess.

chris.


----------



## hmorales (Feb 6, 2006)

usually, on a VBA source code for Access, a way to call a macro is

docmd.runmacro "macroname" 

where macroname is the name of the macro, and it needs to go enclosed in double quotes


----------

