?
Solved

How do I run a macro from another database from within my database

Posted on 2009-04-22
7
Medium Priority
?
392 Views
Last Modified: 2013-11-27
I have a frontend dbs, backend dbs, and another separate database (editStructure dbs) which updates the backend as needed.

I user only opens the frontend
I need the frontend to check to see if the editStructure dbs exists and if it does open it and run the RunUpdate macro.  All while the user is oblivious to this happening.
The RunUpdate macro will execute code which will do something (in this case change a field name to correct a spelling mistake)
I have attached the code used to open the editStructure dbs as needed.
How do I execute the macro RunUpdate (located on EditStructure dbs)?
Function OpenDatabaseRunUpdate(strDbPath As String, strMacroName As String)
    
    Dim wrkJet As Workspace
    Dim dbs As Database
    Dim tbl As TableDef
    Dim fld As Field
    
    ' Create Microsoft Jet Workspace object.
    Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
        ' Open Database object from saved Microsoft Jet database
        ' for exclusive use.
        Set dbs = wrkJet.OpenDatabase(strDbPath, True, False)
            'dbs.DoCmd.RunMacro strMacroName
            'Call dbs.RunUpdate
        dbs.Close
    wrkJet.Close
End Function

Open in new window

0
Comment
Question by:Joe Overman
  • 4
  • 3
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 24210196
Function OpenDatabaseRunUpdate(strDbPath As String, strMacroName As String)
    Dim acObj As Object
   
    Set acObj = CreateObject("Access.Application")
    acObj.OpenCurrentDatabase strDbPath

    acObj.DoCmd.RunMacro (strMacroName)
    acObj.CloseCurrentDatabase
    Set acObj = Nothing


End Function
0
 
LVL 8

Author Comment

by:Joe Overman
ID: 24210263
Is there a way to stop the user from accepting the allow macros question?
0
 
LVL 8

Author Comment

by:Joe Overman
ID: 24224224
Any ideas Capricorn1?
0
Industry Leaders: 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!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24224601
what exactly do you mean?
0
 
LVL 8

Author Comment

by:Joe Overman
ID: 24224643
Your solution allows the macro to run like I need.  But I want it to be invisible to the user.  So what happens is the access application is opened and the user answer the security question.  Can I somehow bypass the security question?
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 2000 total points
ID: 24225693
0
 
LVL 8

Author Closing Comment

by:Joe Overman
ID: 31573530
Thanks Capricorn1
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

839 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