[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Run Access Macro from Vb.net

Posted on 2010-08-13
4
Medium Priority
?
2,858 Views
Last Modified: 2012-05-10
When I run the following code to run an access macro from vb.net I get "Microsoft Office Access can't open the database because it is missing, or opened exclusively by another user."

The database is not missing or opened.
Private Sub RunMacro()
        Dim oAccess As Object
        Try
            oAccess = CreateObject("Access.Application")
            ' Open the database
            oAccess.OpenCurrentDatabase(PickTickMDBLocation, False)

            Try
                oAccess.DoCmd.RunMAcro("test")
                oAccess.DoCmd.Maximize()
                oAccess.Visible = False
            Catch ex As Exception
                sErrNo = Err.Number.ToString
                sError = "RunMacro" & vbCrLf & Err.Description & " " & "ErrNo: " & sErrNo
                dispError(sError)
            Finally
                oAccess.CloseCurrentDatabase()
                oAccess.Quit()
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
                GC.Collect()
            End Try
        Catch ex As Exception
            sErrNo = Err.Number.ToString
            sError = "RunMacro" & vbCrLf & Err.Description & " " & "ErrNo: " & sErrNo
            dispError(sError)
        End Try
    End Sub

Open in new window

0
Comment
Question by:Delta7428
[X]
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
  • 3
4 Comments
 

Author Comment

by:Delta7428
ID: 33436286
I am getting "Type Access.Application is not defined"

I have included the reference to Microsoft Access object library in COM.
Sub RunMacro()
        Dim Adb As New Access.Application
        Adb.OpenCurrentDatabase("PickTickMDBLocation")
        Adb.Run("test")
        Adb.CloseCurrentDatabase()
        Adb.Quit()

    End Sub

Open in new window

0
 

Author Comment

by:Delta7428
ID: 33445487
I added Imports Microsoft.Office.Interop.  That got rid of "Type Access.Application is not defined."

Now I am getting this again:
"Microsoft Office Access can't open the database because it is missing, or opened exclusively by another user."

Please help
0
 

Accepted Solution

by:
Delta7428 earned 0 total points
ID: 33445844
I'm not sure what the difference is, but this works for me.
RunMacro3("test")

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

        oAccess = CreateObject("Access.Application")
        ' Open the database
        oAccess.OpenCurrentDatabase("c:\test.mdb")
        Try

            oAccess.DoCmd.RunMAcro(sMacro)
            oAccess.Visible = False
        Catch e As Exception
            MsgBox("Macro is cancelled or does not exist")
        Finally
            oAccess = Nothing
        End Try
    End Sub

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

650 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