|
-
Feb 2nd, 2005, 09:19 AM
#1
Thread Starter
Frenzied Member
Calling a MSAccess macro
Is there a way that I can call a MSAcess macro in a closed database from VB 6.0? Thanks for any help.
-
Feb 2nd, 2005, 10:22 AM
#2
Re: Calling a MSAccess macro
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" ...
-
Feb 2nd, 2005, 10:52 AM
#3
Thread Starter
Frenzied Member
Re: Calling a MSAccess macro
 Originally Posted by RhinoBull
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" ...
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.
-
Feb 2nd, 2005, 11:25 AM
#4
Re: Calling a MSAccess macro
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
-
Feb 2nd, 2005, 11:59 AM
#5
Re: Calling a MSAccess macro
 Originally Posted by Besoup
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.
Oops, sorry about that ... here we go:
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
-
Feb 2nd, 2005, 01:44 PM
#6
Thread Starter
Frenzied Member
Re: Calling a MSAccess macro
 Originally Posted by RhinoBull
Oops, sorry about that ... here we go:
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.
-
Feb 2nd, 2005, 06:33 PM
#7
Re: Calling a MSAccess macro
You must add a reference to the Microsoft Access xx.x Object Library
-
Feb 2nd, 2005, 08:29 PM
#8
Re: Calling a MSAccess macro
 Originally Posted by Besoup
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.
You should've had simply follow my instructions:
'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
-
Feb 2nd, 2005, 08:33 PM
#9
Re: Calling a MSAccess macro
But either way, the reference must still be there.
-
Feb 2nd, 2005, 08:34 PM
#10
Re: Calling a MSAccess macro
No, not at all. But MS Access must be installed.
-
Feb 2nd, 2005, 08:38 PM
#11
Re: Calling a MSAccess macro
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 2nd, 2005, 08:46 PM
#12
Re: Calling a MSAccess macro
Yea, that's what I said ..
-
Feb 2nd, 2005, 08:51 PM
#13
Re: Calling a MSAccess macro
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.
-
Feb 2nd, 2005, 09:07 PM
#14
Re: Calling a MSAccess macro
Just put Access.Application in quotes:
Set AccessDB = CreateObject("Access.Application")
-
Feb 2nd, 2005, 09:11 PM
#15
Re: Calling a MSAccess macro
That should do it, just like RB said. "ClassName.ServerName" as string.
Edit: I think there is an echo here?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 2nd, 2005, 09:16 PM
#16
Re: Calling a MSAccess macro
That did it!
Last edited by dglienna; Feb 2nd, 2005 at 09:23 PM.
-
Feb 2nd, 2005, 09:24 PM
#17
Re: Calling a MSAccess macro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|