How to run a procedure in a database from code in another DB?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dsatino
    Contributor
    • May 2010
    • 393

    How to run a procedure in a database from code in another DB?

    Basically, there is a pre-existing procedure in a DB. I want to to be able to run this procedure from a different DB.

    Can this be done?
    If so, how?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Yes it can be done. Let's assume that you have an External Database named Test.mdb in the C:\Test Folder, namely: C:\Test\Test.md b. To Execute a Public Sub-Routine named CountTablesInDB () in the External Database (Test.mdb), execute the following Code from the Current Database:
    Code:
    Dim appAccess As Access.Application
    
    'Create instance of Access Application object.
    Set appAccess = CreateObject("Access.Application")
        
    'Open Test Database in Microsoft Access window.
    appAccess.OpenCurrentDatabase "C:\Test\Test.mdb", False
        
    'Run Sub procedure.
    appAccess.Run "CountTablesInDB"
    
    Set appAccess = Nothing

    Comment

    • dsatino
      Contributor
      • May 2010
      • 393

      #3
      Perfect. Thanks a million.

      Comment

      Working...