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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run code from external database.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi all.

I have an Access XP database which has an export routine in it. I am trying to call this routine from another database, passing arguments to it, but am unable to see how to do so. Can anyone help?

Regards,
Mr Big
 
I've not done this before, so I'm winging it a little, but what I think you need to do is set a reference (in tools/references) and then you should be able to call the code in the external database as if it were local.

HTH

Ben ----------------------------------------
Ben O'Hara
----------------------------------------
 
Try this bit of code. I use it all the time

Public Sub RunRemote(dbpath As String, ProcedureName As String, Optional Params As String)

'Note that dbpath is the complete path including the ".mdb" of the remote database

Dim appaccess As Access.Application

Set appaccess = CreateObject("Access.application.8")
appaccess.OpenCurrentDatabase dbpath
If Params = "" Then
appaccess.Run ProcedureName
Else
appaccess.Run ProcedureName, Params
End If
appaccess.Quit
Set appaccess = Nothing
End Sub

Hope this helps

Lenny
 
To call a procedure in another database, try this:

Function CallProcInAnotherDataBase()
Dim myDb As String
' set path and name of db to open
myDb = "C:\Access 2000\Samples\RecordLocks\RecordLocks.mdb"
Dim objAccess As Application
' open a new Access
Set objAccess = New Access.Application
' open the other database
objAccess.OpenCurrentDatabase myDb
' run the procedure desired
objAccess.Run "TestThis"
' close the other database
objAccess.CloseCurrentDatabase
' clear memory
Set objAccess = Nothing
End Function
 
Many thanks to oharab and LennyL. Have decided to create a macro from the program that contains the export function, and automate that process in msdos as a batchfile, but will keep this information for future use. It WILL come in very handy

Thanks again,
Mr Big.
 
Hi.

I tried this, but the export routine itself needs to see the tables and can't from the external database!

The external database (shall we say A.mdb) calls the export routine in the other database (B.mdb), but cannot see the data (tables) in that database (B.mdb).

Therefore, the export routine runs, but does not export any data.

I think I will have to rewrite the export routine and rethink.

Regards,
Mr Big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top