Here is what I'm trying to accomplish with ADO connections:
In excel, user clicks button:
1) open access database "DPS.mdb
2) run macro name "DPSfile" in access
3) query named "DPS#3: is populated with information
4) copy dps#3 into excel sheet named "actual"
5) close access
This is what I started with not using ADO, and it worked once. Now when I run it again, the query is being pulled from another location from c:\mydocuments. I thought it be better to use ADO versus the query refresh method.
Private Sub obtaincmmsdata_Click()
Dim obtaincmmsdata As String
Dim AC As Object
Set AC = CreateObject("access.appli
cation")
AC.Visible = False
AC.opencurrentdatabase (w:\DPS.mdb)
With AC
.DoCmd.RunMacro "DPSfile"
.Quit
End With
Sheets("Actual").Select
Range("E2").Select
Selection.QueryTable.Refre
sh BackgroundQuery:=False
End Sub
The DPSfile is a database that opens several tables and run multiple queries to get the final data in the correct orientation that I need. The final result of the macro in access is query named DPS#3. The sql view of DPS#3 is
TRANSFORM Sum([BTS TEST].PROD) AS SumOfPROD
SELECT [Department Table].CD_AREA AS Area, "Actual" AS Product, [Department Table].DS_WORK_CNTR AS DepartmentName, [Department Table].NO_WORK_CNTR AS WorkCenter
FROM [Department Table] LEFT JOIN [BTS TEST] ON [Department Table].NO_WORK_CNTR=[BTS TEST].NO_WORK_CNTR
WHERE ((([Department Table].NO_WORK_CNTR)="0" Or ([Department Table].NO_WORK_CNTR)="6637
F" Or ([Department Table].NO_WORK_CNTR)="6637
A" Or ([Department Table].NO_WORK_CNTR)="6669
A" Or ([Department Table].NO_WORK_CNTR)="6668
3" Or ([Department Table].NO_WORK_CNTR)="6668
2" Or ([Department Table].NO_WORK_CNTR)="6634
F" Or ([Department Table].NO_WORK_CNTR)="6634
A" Or ([Department Table].NO_WORK_CNTR)="6631
A" Or ([Department Table].NO_WORK_CNTR)="6669
7" Or ([Department Table].NO_WORK_CNTR)="6627
F" Or ([Department Table].NO_WORK_CNTR)="6627
A" Or ([Department Table].NO_WORK_CNTR)="6633
F" Or ([Department Table].NO_WORK_CNTR)="6633
A" Or ([Department Table].NO_WORK_CNTR)="6631
F" Or ([Department Table].NO_WORK_CNTR)="6632
F" Or ([Department Table].NO_WORK_CNTR)="6632
A" Or ([Department Table].NO_WORK_CNTR)="6627
E" Or ([Department Table].NO_WORK_CNTR)="6627
B" Or ([Department Table].NO_WORK_CNTR)="6668
9" Or ([Department Table].NO_WORK_CNTR)="6668
8" Or ([Department Table].NO_WORK_CNTR)="6668
7" Or ([Department Table].NO_WORK_CNTR)="6668
1" Or ([Department Table].NO_WORK_CNTR)="6667
6"))
GROUP BY [Department Table].CD_AREA, "Actual", [Department Table].DS_WORK_CNTR, [Department Table].NO_WORK_CNTR
PIVOT [BTS TEST].[DAY OF THE WEEK];
I was thinking of adding ADO after I run the macro in my above code, and then copy this query into excel, and then close access and the connection.
I appreciate any help you could provide. I'm not familiar with the ADO commands, but I'm willing to learn
Start Free Trial