1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Calling a VBA access macro from an Access VBA procedure

Discussion in 'Business Applications' started by PincivMa, Mar 21, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    335
    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
     
  2. Simon71

    Simon71

    Joined:
    Feb 9, 2005
    Messages:
    147
    Mario,

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

    call proceedureName()

    Hope this helps,

    Simon
     
  3. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    18,834
    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".
     
  4. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    335
    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
     
  5. cristobal03

    cristobal03

    Joined:
    Aug 5, 2005
    Messages:
    3,072
    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.
     
  6. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    335
    OK Chris

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

    Mario
     
  7. cristobal03

    cristobal03

    Joined:
    Aug 5, 2005
    Messages:
    3,072
    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:

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

    chris.
     
  8. hmorales

    hmorales

    Joined:
    Feb 6, 2006
    Messages:
    36
    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
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/451560