Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I execute a function in another database? 2

Status
Not open for further replies.

lifter10

MIS
Dec 3, 2003
45
US
I have one Access(1) database that I would like to run a specific function in another Access(2) database. How can this be done? Basically, the function in the other(2) database runs some code and then executes a make-table query that makes a table in my first(1) database.

Thanks in advance,

Chris
 
Create a reference to your 2nd database. Open a module and select Tools|References and browse to your 2nd database. Then call the routine as if it were in the 1st database.
 
Wow, I've had two easy questions today. Thanks for the response! Maybe I could use my head a little today.

Thanks again,

Chris
 
This is exactly what I was looking for, however....I made the reference to the other database. I did a docmd.open query but it didn't work.

Do you have some sample code?
 
Suppose you have 2 databases: A and B. B contains a function (i.e. GetUserName) that you wish to call from A. In database A, set a reference to database B. And from A call the function like this:

Call GetUserName()

or

GetUserName
 
If both databases have a function called GetUserName(), how do I tell it which to run?

Also, I want to run a query in database B from database A. Do I need to open database B? If so How?
 
I believe Access first trys to find the function in the current database (A). If it doesn't exist then it attempts to find it in the referenced database (B).

The easiest way to run a query from another database would be to create a function in the 2nd database (B) that executes the query. Then call the function from the first database (A). (I think that will work.) Otherwise, you are going to have to open the 2nd database via the OpenDatabase method.
 
Thanks. I'll give it a try and let you know.
 
As FP said, the DBase, will always search for the local function/procedure first.
To avoid naming conflicts with libraries, you reference the module name, then the procedure/function, [mdlGetUserName].GetUserName()

This way, you CAN have 2 function/procedures, of the same name, between the 2 DBases.

Hope this helps, good luck!
 
This stuff is GREAT!! Thanks!

Can I also share variables between the two databases? I have a field in a form in Database A that the queries in both databases use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top