Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.Net Run Access Macro

Posted on 2004-04-16
5
Medium Priority
?
1,431 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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 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