Multi Database Functions

K

Kjuib

I have some Functions in Database1 that I would like to
initate in Database2. This function will update files in
Database1. I do not want to make it into a macro.. nope
not at all. I have the following code, but it does not
work:
Sub AccessNOA2()
Dim A As Object
Set A = CreateObject("Access.Application")
With A
.Visible = False
.OpenCurrentDatabase ("C:\")
.DoCmd.SetWarnings False
MsgBox ("Time to Copy")
.Call "FactorTableTransfer('client', 'NewClient')"
.DoCmd.Close
End With
End Sub


FactorTableTranser() is my function I want to use. Anyone
able to help me with this?
 
S

SA

1.) First you should make it a function in your db 1
2.) Second in Db2, simply add a reference to db 1 in the Tools -> References
dialog once you are in the Visual basic editor

Then you can call the function in db 1 as if it were native to db2.

The other method is a bit more cumbersome if you don't want to add a
reference. In that instance you have to use automation to launch db 1 and
run its function as in:

Dim objAcc as Object
Set objAcc = CreateObject ("Access.Application")
objAcc.OpenCurrentDatabase("x:\somedir\somedb.mdb")
objAcc.Run "YourFunctionName"
doevents
objAcc.Quit
 
D

Douglas J. Steele

Sub AccessNOA2()
Dim A As Object
Set A = CreateObject("Access.Application")
With A
.Visible = False
.OpenCurrentDatabase ("C:\")
.DoCmd.SetWarnings False
MsgBox ("Time to Copy")
.Run "FactorTableTransfer", 'client', 'NewClient'
.DoCmd.Close
End With
End Sub

(I assume that you've got a complete path for the OpenCurrentDatabase
statement, not just C:\)

See http://support.microsoft.com/?id=210111 for more about Automation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top