Export from multiple Access Queries to Multiple Workbooks and Worksheets

TSchaff

New Member
Joined
May 16, 2018
Messages
2
I have a DB that culminates into 4 export queries. I would like to create a macro to export the 4 queries into one workbook per Business Unit. There are 10+ Business Units. A single Business Unit workbook would contain the output of from each of the export queries for the respective Business Unit.

Help!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
create a form ,on it is a listbox of all business units.
the code will cycle thru the list, and export the query based on the bus.unit

the query uses the listbox, lstUnit , to pull data, ie:
select * from table where [busUnit]=forms!myForm!lstUnit

Code:
sub btnMake_click()
dim i as integer
dim sUnit as string 
dim vFile


for i = 0 to lstUnit.listcount - 1
   sUnit = lstUnit.ItemData(i)   'get next item in list
   lstUnit = sUnit              'set list to that item

   vFile = "c:\temp\" & sUnit & ".xlsx"

   DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qsExport1UnitPayments", vFile, True,"Payments"
   DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qsExport1UnitChrgs", vFile, True,"Charges"

next
end sub
 
Last edited:
Upvote 0
No sure I fully understand how this works or how to implement for my specific tables and queries?
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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