Using VBA (in Excel) to open Access Database, run some queries, then export queries and tables back to Excel

mattmickle

Board Regular
Joined
Nov 17, 2010
Messages
81
OK,
Not sure if I'm explaining this right:

I have a fairly extensive, VBA heavy spreadsheet that requires weekly data updates.
From this worksheet, I would like to open the Access Database where the data resides, run one query and export those results, then export 3 complete tables as well.

Here's my code so far:
Code:
Option Explicit

Sub CHANGE_FORM_EXPORTS()
On Error GoTo CHANGE_FORM_EXPORTS_Err
    Dim MyAccess As Object
    Set MyAccess = CreateObject("Access.Application")
    MyAccess.Visible = True
    MyAccess.OpenCurrentDatabase ("[URL="file://\\golub.com\depts\HR-Share\Salary"]\\golub.com\depts\HR-Share\Salary[/URL] Admin\Salary.mdb")
    
    Application.DisplayAlerts = False
     
    DoCmd.OpenQuery "CHANGE_FORMS_2014"
    DoCmd.Close acQuery, "CHANGE_FORMS_2014"
    DoCmd.RunSavedImportExport "Export-CHANGE_FORMS_2014"
    DoCmd.OpenTable "Job Table - With Areas - CURRENT"
    DoCmd.Close acTable, "Job Table - With Areas - CURRENT"
    DoCmd.RunSavedImportExport "Export-Job Table - With Areas - CURRENT"
    DoCmd.OpenTable "Store Supervisors"
    DoCmd.Close acTable, "Store Supervisors"
    DoCmd.RunSavedImportExport "Export-Store Supervisors"
    DoCmd.OpenTable "Combined Supervisors Table"
    DoCmd.Close acTable, "Combined Supervisors Table"
    DoCmd.RunSavedImportExport "Export-Combined Supervisors Table"

CHANGE_FORM_EXPORTS_Exit:
    Exit Sub
CHANGE_FORM_EXPORTS_Err:
    MsgBox Error$
    Resume CHANGE_FORM_EXPORTS_Exit
    Application.DisplayAlerts = True
End With

End Sub

but it doesn't like the DoCmd when i run it. I'm using Excel 2007 and Access 2007.
Any help would be greatly appreciated.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,196,254
Messages
6,014,270
Members
441,810
Latest member
LouLou1234

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top