Is it possible to use the command "DoCmd.RunSql" in relation to a different database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bankowiec31
    New Member
    • Jun 2015
    • 1

    Is it possible to use the command "DoCmd.RunSql" in relation to a different database

    Is it possible to use the command "DoCmd.RunS ql" in relation to other database than the current database?

    ACCESS 2010 code:
    Code:
    Dim db1 As Database, db2 As Database
    Set db1 = CurrentDb
    Debug.Print db1.Name            'returns c:\Users\Kombi\Documents\Database1.accdb
    
    Set db2 = OpenDatabase("c:\Users\Kombi\Documents\Database2.accdb")
    
    'table1 is in c:\Users\Kombi\Documents\Database1.accdb
    DoCmd.RunSQL "drop table table1"            'it works OK
    
    'table2 is in c:\Users\Kombi\Documents\Database2.accdb
    'I would like to use something like this:
    DoCmd.RunSQL "drop table table2"
    Last edited by Rabbit; Jun 30 '15, 10:14 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Best I recall, the syntax is:
    Code:
    DoCmd.RunSQL "drop table table2 in 'c:\Users\Kombi\Documents\Database2.accdb'"
    Test at your own peril :)

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      TheSmileyCoder: matches the code in one of the databases I've inherited and the code that I found online.

      Comment

      Working...