Is there a way to open macro

Hi,

I have a project in VB and it connects to a Access database. And there is a macro in my Access database, which opens a table in that database.

I want to create a button, so that when i click on the button, the macro in Access will be executed.

Is there a way to do this by using functions provided in VB 2005 express or writing some code to do it

Thanks.




Answer this question

Is there a way to open macro

  • Xiaowei Jiang

    hi,

    How can i do this

    " Add the Office Primary Interop Assemblies onto you machine.

    Add a reference to Microsoft Office Interop Access and then use something like the following code."

    I tried to add a reference to Microsoft Access 11.0 Object Library, but there is error show that Microsoft.Office.Interop.Access.Application is not defined.

    Thanks



  • Scott Forbes

    Hi,

    Thanks for your reply. I run this below code and it give me some error message.

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim Adb As New Microsoft.Office.Interop.Access.Application()

    Adb.OpenCurrentDatabase("C:\Documents and Settings\yzhang\My Documents\Visual Studio 2005\Projects\macro\macro.mdb")

    Adb.Run("OpenImportBudget")

    Adb.CloseCurrentDatabase()

    Adb.Quit()

    End Sub

    End Class

    This is the error:

    Microsoft Office Access can't open the database because it is missing, or opened exclusively by another user.

    macro.mdb is my database and OpenImportBudget is the name of my macro created in Access.

    My database is not open and there is no others using this database. could you please suggest some possible reasons which cause this error



  • Sheila1983

    Add the Office Primary Interop Assemblies onto you machine.

    Add a reference to Microsoft Office Interop Access and then use something like the following code.

    Dim Adb As New Microsoft.Office.Interop.Access.Application
    Adb.OpenCurrentDatabase(
    "Path To the database")
    Adb.Run(
    "Macro name to be ran..")
    Adb.CloseCurrentDatabase()
    Adb.Quit()

    Obviously putting in your actual database path and actual macro name


  • mrsamer

  • Marius.Cotor

    I'd check the path is correct and ensure that I could open the database using access. If still causing a problem try restarting the machine and seeing if it works.

    The code checks out here so the message may well be valid for your computer.


  • Is there a way to open macro