Results 1 to 5 of 5

Thread: Is it possible to start an Access macro from Excel using an ADODB.connection?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Is it possible to start an Access macro from Excel using an ADODB.connection?

    From Excel 2007, I'm connected to an Access database via ADODB.Connection. From here, I've retrieved some data from the database into a worksheet. Now I'd like to issue a command to the database to start one if its macros. This macro calls a function that is a VBA module. Can this be done? I know I can issue a DoCmd if I do a 'CreateObject("Access.Application") and a 'OpenCurrentDatabase', but I'm already connected.

    Thanks.

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Is it possible to start an Access macro from Excel using an ADODB.connection?

    If I have the database open already, this seems to do it:

    Code:
    Public Sub getAcc()
        Dim oAcc As Access.Application
        
        Set oAcc = GetObject("c:\yourPath\vbmain.accdb")   'change to your path
        oAcc.DoCmd.RunMacro "macRanFromExcel"   'my macro name
        Set oAcc = Nothing
    End Sub
    I opened it manually first, not through code. Not sure if that will make a difference or not.

    PS: Add reference to Microsoft Access XX.X Object Library first.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Is it possible to start an Access macro from Excel using an ADODB.connection?

    Thanks. Your code is similar to what I mentioned in my initial post (Get/CreateObject) and it works standalone, but it doesn't work for me if I am connected to database via ADODB.Connection. I'm trying to find out if it's possible to start a database macro while I am connected to the database; i.e., I am not starting Access and I am not actually opening the file that is the database.

  4. #4
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Is it possible to start an Access macro from Excel using an ADODB.connection?

    I believe the solution proposed by vbfbryce is your only avenue to invoke a macro. The ADODB connection will be using the provider you specify in your connection string; Jet or more likely ACE. These providers are designed only for database functionality and are not intended to provide application specific functionality like macros.

    You can view the functionality provided by the ACE provider (ACEDAO.DLL) at:

    Microsoft Data Access Objects Reference

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Is it possible to start an Access macro from Excel using an ADODB.connection?

    Thanks. That's what I am beginning to understand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width