Link to home
Start Free TrialLog in
Avatar of sublimation
sublimationFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.Net Run Access Macro

Hello, can you help me to run a macro in Access 2000 from VB.Net.
I can get the databas to open and close fine.

I am using the following code:

            Dim oAccess As Access.ApplicationClass

            oAccess = CreateObject("Access.Application")
            oAccess.Visible = True
            oAccess.OpenCurrentDatabase(strPerson, False)

            oAccess.RunCommand("macro1")   '----------------------------------

            oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
            oAccess = Nothing


I have tried both RunCommand and Run("macro1"), neither work, I get message saying

Cant find Macro1.

Am I using the wron method?
Avatar of Mikal613
Mikal613
Flag of United States of America image

it seems like you dont have a macro called MAcro1 check the spelling and try again.
ASKER CERTIFIED SOLUTION
Avatar of iboutchkine
iboutchkine

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 sublimation

ASKER

Hello, Mikal613.  I really did check the name and spelling of my macro.

It seems that the problem lies in the fact that it want to call a sub procedure and not a macro.  I have a procedure called Macro1 and it runs this fine.

I am not sure of what to do when I answer my own question,  do you know how I can mark my comment as the Accepted answer?
Avatar of iboutchkine
iboutchkine

You can ask community support to close the question and refund the points
Hello, no need for that, iboutchkine.

You code works fine!  I can now run the macro!

Thanks to both of you for the guidance.