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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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