Opening another DB and running macro (passing variables)

alexbah

New member
Local time
Today, 13:58
Joined
Jan 5, 2012
Messages
7
I am trying to open an access database from another database and run a macro in it. I can accomplish this, but I also need to pass variables into the other database's macro for it to run appropriatly.
DB 1: user makes selection on user form and they are stored as variables - macro opens DB2 and calls macro "main"
sub main(variable1, variable 2, variable3, etc..)
I cannot figure out the syntax of how to pass variables when trying to run the macro in the second DB. Is this possible. My code is below:
Dim accapp As Access.Application
Set accapp = New Access.Application
accapp.OpenCurrentDatabase ("C:\Users\123\Desktop\models\RPA V3.accdb"), False
accapp.Visible = True
accapp.Run "main" '------ this is where I need to pass variables into sub routine 'main'
 
Is it calling a macro or is it calling a Sub routine?

It should be calling the Sub. It's also not a good idea to have a macro and a Sub named the same.
 
It is calling a sub routine. 'main' is the name of the sub.
 
How many arguments (or parameters) does it expect?
 
10 parameters. here is what I tried to do:

accapp.Run "main(parentName, RESPORG, UNIT, level, hierarchy(), expectedPerf, date_list, ProjStatus, ProjDate, NTIMS_STATUS)"
 
With the exception of hierarchy(), are all those parameters fields, variables or text?

Also, are all 10 parameters required?
 
they are text, and all required inputs for the sub main to know what to do
 
And hierarchy is a function that returns text too?
 
I might have just found the issue. Main is a function, not a sub. Could this be the problem?
below are the parameter types, hierarhcy() is a string:

Function main(dte As Date, parentName$, RESPORG$, UNIT$, lvl$, hierarchy() As String, PERF#, date_list As Object, ProjStatus As Boolean, ProjDate As Date, NTIMS_STATUS As Boolean)
 
Even as a sub routine, I cannot pass the parameters.
I get an error that says" cannot find procedure 'main(parentName,.....
 
It needs to be a function to return a string yes, but that isn't the problem.

What I meant by the question I asked in post #6 is, in your function call, are these parentName, RESPORG, UNIT, level, hierarchy(), expectedPerf, date_list, ProjStatus, ProjDate, NTIMS_STATUS text values or field names or variable names?

You mentioned they are text but I don't think you understand my question. The reason why I'm posing this question back to you is because they are literally the same names as the actual Function definition in your last post, so I suspect they are actually string variables.
 
Correct, they are string variables, except where noted, such as ProjStatus being Boolean. I don't think I followed your questions and got confused on the terminology
 
In that case you need to expose the variables in the call to the function so that they're not just read as text, they're read as variables. Like so:
Code:
accapp.Run "main", parentName, RESPORG, UNIT, level, hierarchy(), expectedPerf, date_list, ProjStatus, ProjDate, NTIMS_STATUS
Note the format it was written.
 

Users who are viewing this thread

Back
Top Bottom