Solved

VB.Net Run Access Macro

Posted on 2004-04-16
5
1,375 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with Query not working in client's PC 1 35
ADO.NET ENTITY DATA MODEL 3 30
Variable Event ? 3 22
Get Client IP on RDS - VB.NET 15 25
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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

22 Experts available now in Live!

Get 1:1 Help Now