Link to home
Start Free TrialLog in
Avatar of jogmen
jogmen

asked on

Use ADO to call Access Macro

Is it possible to use ADO from VB to call a macro that is resident in an Access Database?

Thanks.
Avatar of chandukb
chandukb

Yes You can call an Access Macro with ADO, Here is the
Code:

You have to add a reference to Microsoft Access Object Library.

Dim AppAccess As Access.Application
Set AppAccess = CreateObject("Access.Application")
AppAccess.OpenCurrentDatabase ("D:\Accessdb\Backup\ITBackup.mdb")

AppAccess.DoCmd.RunMacro "Macro Name"


Chandu
I dont think you can call an Access Macro with ADO
you'l have to do it the way chandukb said
however you can probably do what that macro does with ADO
I have had no success calling macros or functions in Access using ADO. You can call any kind of query or Stored procedure(action query), though.
And Chndukb, that is not using ado, that is just using the APPLICATION object through VB to create an instance of ACCESS.
i_jester69 is absolutely correct. The ADO layer does not permit you to gain access to any user-defined functions or macros within the database. There is an MSDN article on this which I am looking for which explains why this is not allowed. When I find it I will post the link.
There are always workarounds for almost anything.

I have found, when using Access, (or any database, for that matter) that it almost always make sense to use the database to do what it is designed for, ie: Process data, in the form of tables, queries, and procedures.

If there is something that you can do in a query, or even a bunch of stacked queries instead of a function in access, then do it that way. Or you just do everything you possibly can in the database, and perform the function stuff in VB.

And Tim, I didn't even know why it didn't work, I just knew it didn't. The biggest complaint I have with Microsoft always seems to be that sometimes it can be very difficult to cross-reference, or find, help information on certain topics, unless you already know exactly where to look.

                   Happy coding!      Darryn
ASKER CERTIFIED SOLUTION
Avatar of inthedark
inthedark
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jogmen

ASKER

Thanks for all the comments...I just decided to automate Access (as much as I hate to do it) with a quick and dirty app.  Though I'd give inthedark some points, cuz he seemed to put alot of thought (and typing :)) into it.

Cheers!