Run a Sub in another Database

TKnight

Registered User.
Local time
Today, 14:16
Joined
Jan 28, 2003
Messages
181
Hi, I'm trying to run a sub called "Update_DB_Information" in a module in another database. The code refernces the DB fine (if I replaces the ###'s with a DoCmd it works) but I don't know how to call a sub this way. I've tried just putting the sub name, and putting the module name then sub name but I can't get it to work, can anyone help, thanks, Tom.

Sub UpdateExternalInfo(strDB As String)

' Return reference to Microsoft Access Application object.
Set appAccess = New Access.Application

' Open database in Microsoft Access.
appAccess.OpenCurrentDatabase strDB
appAccess.##########

MsgBox "DB Information is Updated"
appAccess.CloseCurrentDatabase
Set appAccess = Nothing
End Sub
 
Hello,

Not tested, but I suppose it will work with:
appAccess.YourModule.Update_DB_Information

YourModule is the name of the module that contains the sub.
 
I've only done this once, but here is the code:

'total path of the db you want to open
Const strpath As String = "\\READINMABOP1\DGarriso$\rosemont\MonthlyClosings.mdb"
Dim objAccess As Object
Dim ctr As Date
Set objAccess = GetObject(strpath) 'opens other db
objAccess.Run ("exportexcel") 'runs function in other db
objAccess.Quit 'quits other db
Set objAccess = Nothing

Hope this helps
 
Thanks guys
SforSoftware, i tried that and it didn't work (why though i've got no idea)

Dgar007 that would work but I think it would actually open up the other Db whereas mine executes without the Db actually opening on screen.
I got round it in the end by writing a function that called the sub then using DoCmd.RunCode to call the function.
The long way round i'm sure but it works!
Thanks again, Tom
 

Users who are viewing this thread

Back
Top Bottom