Is there a way that I can call a MSAcess macro in a closed database from VB 6.0? Thanks for any help.
Printable View
Is there a way that I can call a MSAcess macro in a closed database from VB 6.0? Thanks for any help.
Just use Excel's Run method:
VB Code:
Dim excl As Excel.Application Dim wrbk As Workbook Set excl = New Excel.Application excl.DisplayAlerts = False Set wrbk = excl.Workbooks.Open("myfile", , True, , "mypassword") excl.Run "MacroName", "arg1", "arg2" ...
Quote:
Originally Posted by RhinoBull
Thanks, but I am trying to run a macro inside of a MSAccess database that runs a series of queries within that database. Or even call a module inside that DB.... any help is appreciated.
substitute access for excell it is the same principal
effectively you open an access object then can access all the properties and methods within including the macro
rgds pete
Oops, sorry about that ... here we go:Quote:
Originally Posted by Besoup
VB Code:
Public Sub RunAccessMacro(strDB As String, strMacro As String) '================================================================ 'for late binding declare it As Object and use CreateObject() function Dim AccessDB As Access.Application Set AccessDB = New Access.Application With AccessDB .OpenCurrentDatabase strDB .DoCmd.RunMacro strMacro, 1 '.Visible = True 'you decide .CloseCurrentDatabase End With Set AccessDB = Nothing End Sub
Thanks, tried this but keep getting "User-defined type not defined". Besides that the rest looks like exactly what I am looking for with the visibity false ofcourse.Quote:
Originally Posted by RhinoBull
You must add a reference to the Microsoft Access xx.x Object Library
You should've had simply follow my instructions:Quote:
Originally Posted by Besoup
'for late binding declare it As Object and use CreateObject() function
VB Code:
Dim AccessDB As Object Set AccessDB = CreateObject(Access.Application) 'rest is the same
But either way, the reference must still be there.
No, not at all. But MS Access must be installed.
For early binding a reference must be added to your project. For late binding no
references are required. Either way, the target system must have the
required dependency files installed.
Yea, that's what I said .. ;) :p
I have Access installed, and it doesn't work for late binding. Says that Access is not defined.
VB Code:
Public Sub RunAccessMacro(strDB As String, strMacro As String) '================================================================ 'for late binding declare it As Object and use CreateObject() function Dim AccessDB As Object Set AccessDB = CreateObject(Access.Application) With AccessDB .OpenCurrentDatabase strDB .DoCmd.RunMacro strMacro, 1 '.Visible = True 'you decide .CloseCurrentDatabase End With Set AccessDB = Nothing End Sub
Compiler Error: Variable Not Defined.
Just put Access.Application in quotes:
Set AccessDB = CreateObject("Access.Application")
That should do it, just like RB said. "ClassName.ServerName" as string.
Edit: I think there is an echo here? :p
That did it! ;)
LOL ... :lol: :lol: :lol: :lol: :lol:Quote:
Originally Posted by RobDog888