Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

Calling a VBA access macro from an Access VBA procedure


(!)

PincivMa's Avatar
PincivMa PincivMa is offline
Member with 321 posts.
THREAD STARTER
 
Join Date: Mar 2004
21-Mar-2006, 10:51 AM #1
Calling a VBA access macro from an Access VBA procedure
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's Avatar
Simon71 Simon71 is offline
Senior Member with 147 posts.
 
Join Date: Feb 2005
Experience: Intermediate
21-Mar-2006, 11:47 AM #2
Mario,

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

call proceedureName()

Hope this helps,

Simon
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,667 posts.
 
Join Date: Mar 2005
Location: UK
21-Mar-2006, 01:29 PM #3
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".
__________________
OBP
I do not give up easily
PincivMa's Avatar
PincivMa PincivMa is offline
Member with 321 posts.
THREAD STARTER
 
Join Date: Mar 2004
21-Mar-2006, 04:33 PM #4
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's Avatar
Member with 3,072 posts.
 
Join Date: Aug 2005
Experience: Advanced
22-Mar-2006, 11:38 AM #5
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's Avatar
PincivMa PincivMa is offline
Member with 321 posts.
THREAD STARTER
 
Join Date: Mar 2004
22-Mar-2006, 11:51 AM #6
OK Chris

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

Mario
cristobal03's Avatar
Member with 3,072 posts.
 
Join Date: Aug 2005
Experience: Advanced
22-Mar-2006, 11:58 AM #7
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.
hmorales's Avatar
hmorales hmorales is offline
Member with 36 posts.
 
Join Date: Feb 2006
Experience: Advanced
22-Mar-2006, 02:50 PM #8
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
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2