Main Page ┬╗ MS Access Snippets ┬╗ Run Queries From Other Access Files


Run Queries From Other Access Files


You can run queries from other MS Access databases sequentially. Just modify the code below according to your needs.
Here is the code:

sample.txt
Option Compare Database
Function Run_Queries_From_Other_Access_Files()
'   If you wish, you can comment (put single quote ( ' )  character to beginning of line) line below to see 
'   warning messages like "You are about to run a make-table query that will modify data in your table"
DoCmd.SetWarnings False
Dim db As DAO.Database
'   If you wish, you would change  OpenDatabase(Application.CurrentProject.Path & "\" & "Sample_Access_File_One.accdb")  
'   to full path like OpenDatabase(c:\Temp\Sample_Access_File_One.accdb")
'   In my design, all of the access file have to be in same folder with Run_Queries_From_Other_Access_Files.accdb file.
'FILE ONE
Set db = DBEngine.Workspaces(0).OpenDatabase(Application.CurrentProject.Path & "\" & "Sample_Access_File_One.accdb")
db.Execute "MAKE_TABLE_QUERY_ONE", dbFailOnError
Set db = Nothing
'FILE TWO
Set db = DBEngine.Workspaces(0).OpenDatabase(Application.CurrentProject.Path & "\" & "Sample_Access_File_Two.accdb")
db.Execute "MAKE_TABLE_QUERY_TWO", dbFailOnError
Set db = Nothing
MsgBox "Congratulations! Process Completed!", vbInformation, "MCuma"
End Function

When running completed you will see Msgbox. Then please open Sample_Access_File files, you will see result table which are named UNITED_TABLE.
You can download running sample from below link.
Download example file


´╗┐