access vba to run query and create folder to export data into.

iP_123

Board Regular
Joined
Apr 18, 2016
Messages
99
Hi.
I manually run a monthly access query (not a make table query) that produces 10 query results that I in-turn copy and paste each results into an excel workbook in a specified folder. I paste all the results of the query into five separate workbooks in the current month folder but on different tabs (two data tabs in each workbook)...
Is there a way to have a vba in access that will run the query, then create a folder each month like ((01) - Jan Sales Report) and export the query results data into 5 separate workbooks in this folder eg. (WorkBook1, WorkBook2, WorkBook3 etc).
I currently use MS Access 2013 but will soon upgrade to 2016.

I very much appreciate the assistance.
ip_123
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Yes, but it certainly would be more than a few lines of code. What's your proficiency with Access vba?
Some things aren't clear, at least to me, so a simplified answer is the best I can do (besides the yes part).
You'd need a procedure that either transfers the data using the built in TransferSpreadsheet function, or loop through a recordset and copy to Excel via Automation.
In addition, your procedure will need the msoFileDialogFolderPicker to select the target folder.

For automation, see http://www.accessmvp.com/kdsnell/EXCEL_Export.htm#WriteRstFile for example.
 
Upvote 0
Thank you Micron. I am not proficient in Access vba but with your direction and reference you highlighted in your response I will try to create something similar.
I appreciate your time and guidance.

Thanks again.
ip_123
 
Upvote 0
You're welcome.
When you research the folder picker part, don't confuse the msoFileDialogFilePicker with the msoFileDialogFolderPicker (assuming I'm remembering their correct names). As their names suggest, one returns the folder chosen, and IIRC, won't show you files in that folder. The other will list files and allow you to choose from them. From what I can gather from your original post, you want to navigate to a folder. Thus, the function would return the folder path and your code would save the file into that folder by concatenating the file name to the path. You would have to ensure that you add the slash between the returned path and the file name.
Good luck.
 
Upvote 0

Forum statistics

Threads
1,223,565
Messages
6,173,087
Members
452,500
Latest member
FrankSit

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