Solved

VB.Net Run Access Macro

Posted on 2004-04-16
5
1,363 Views
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.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?
0
Comment
Question by:sublimation
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

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

Accepted Solution

by:
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.OpenCurrentDatabase(fsDBName)
        Try
            oAccess.DoCmd.RunMAcro(sMacro)
            oAccess.DoCmd.Maximize()
            oAccess.Visible = True
        Catch e As Exception
            MsgBox("Macro is cancelled or does not exist")
        Finally
            oAccess = Nothing
        End Try
    End Sub
0
 
LVL 4

Author Comment

by:sublimation
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?
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 10843822
You can ask community support to close the question and refund the points
0
 
LVL 4

Author Comment

by:sublimation
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.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Free Alternative to JIRA 4 58
crm development 2 37
Default parameter problem in C# 3 27
How to open a link from vb.net app 3 9
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now