VB.Net Run Access Macro

Posted on 2004-04-16
Last Modified: 2012-05-04
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 = Nothing

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

Cant find Macro1.

Am I using the wron method?
Question by:sublimation
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 48

Expert Comment

ID: 10843634
it seems like you dont have a macro called MAcro1 check the spelling and try again.
LVL 28

Accepted Solution

iboutchkine earned 500 total points
ID: 10843793
this works fine for me

Private Sub RunMacro(ByVal sMacro As String)
        Dim oAccess As Object

        oAccess = CreateObject("Access.Application")
        ' Open the database
            oAccess.Visible = True
        Catch e As Exception
            MsgBox("Macro is cancelled or does not exist")
            oAccess = Nothing
        End Try
    End Sub

Author Comment

ID: 10843794
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?
LVL 28

Expert Comment

ID: 10843822
You can ask community support to close the question and refund the points

Author Comment

ID: 10843843
Hello, no need for that, iboutchkine.

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

Thanks to both of you for the guidance.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question