• Run macro from a separate DB??

    Author
    Topic
    #356561

    Is it possible to be in a database (I will call it dbAlpha) and run a macro from another database (dbBravo, macro is called Charlie)?

    Can this be done from the macro line or is it some type of code.

    Please help. help steve69 grovel

    Viewing 1 reply thread
    Author
    Replies
    • #527991

      You can’t “attach” a macro. And you won’t be able to call one in another database except from code. The big question is why you would want to do this at all. Access macros are no substitute for code, lack error handling, and complex macros are at least as difficult to write as simple code would be.

      • #528010

        The two databases track different items, one for operator productivity and the other tracks operator errors and corrective actions.

        Month End Reports get ran out of both dbs. In the past I would run all the reports and break them down for distribution. However, I am now trying to automate the printing of the reports for one of my assistants.

        I was looking for a way to run all the reports at once without having to open each database.

        steve69 sigh

        • #528011

          Hi. This subject interests me too. I have three databases which run reports automatically at night. I have built a forth database which backs up and compacts the other three, but of course, this can’t be done if the databases are open. What i have mananaged to do is run macros within the three from the forth using run msaccess.exe /db name etc (actual code on request), but i am sure it must be possible to run code remotely by creating a workspace??? I agree, running macros is not at all nice compared to running code, which is why i would love to get this sorted out.

          At the moment i have to leave all four open, and then rely on a whole bunch of timers to run reports and close each app. down before the timer on the compactor kicks in, but i really would like to be able to “control” each of the three from the fouth.

    • #528022

      At the risk of inviting Charlotte’s wrath…. warts
      Here’s a code example you can use:

      Function RunExternalReport()
          Dim AccessApp As New Access.Application
          Dim strDB As String
          strDB = "C:Program FilesMicrosoft OfficeOfficeSamplesNorthwind.mdb"
          AccessApp.OpenCurrentDatabase strDB
          AccessApp.DoCmd.OpenReport "Report1", acViewNormal
          AccessApp.CloseCurrentDatabase
          Set AccessApp = Nothing
      End Function

      Of course, you’ll want to add error handling but this is the general idea. After the OpenCurrentDatabase command, you can use the DoCmd object (or any other object for that matter) of the external database to do anything you need.

      HTH thumbup

      • #528044

        I’m not flinging any warts for code, Mark, only for trying to run macros remotely, which can cause serious scars when it crashes and burns on you. grin

      • #528084

        I also have a date field in the second database that I would like to link prior to running this code (which works very well, thanks). Can I add a line to the code like?

        set [table1].[startdate] = [table2].[startdate]

        Do I need to specify the db name in the equation? How do I specify a db name that contains spaces?

        sorry for the multiple questions.

        steve69 doh

    Viewing 1 reply thread
    Reply To: Run macro from a separate DB??

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: