Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    May 2001
    Location
    Omaha, NE USA, Nebraska, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run macro from a separate DB??

    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. <img src=/S/help.gif border=0 alt=help width=23 height=15> steve69 <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23>

  2. #2
    ravey
    Guest

    Re: Run macro from a separate DB??

    I'm not 100% sure, but I think you could do that by Attaching the macro, then you could just run it as if it was in the same mdb. But why would you want to? You could just import it, to save you the trouble of rewriting it. Maybe you have some other reason to do it this way?

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Run macro from a separate DB??

    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.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    May 2001
    Location
    Omaha, NE USA, Nebraska, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run macro from a separate DB??

    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 <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    Barnsley, Yorkshire, England
    Posts
    108
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run macro from a separate DB??

    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.

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run macro from a separate DB??

    At the risk of inviting Charlotte's wrath.... <img src=/S/warts.gif border=0 alt=warts width=59 height=24>
    Here's a code example you can use:<pre>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</pre>

    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 <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Run macro from a separate DB??

    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. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

  8. #8
    2 Star Lounger
    Join Date
    May 2001
    Location
    Omaha, NE USA, Nebraska, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run macro from a separate DB??

    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 <img src=/S/doh.gif border=0 alt=doh width=15 height=15>

Posting Permissions

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