Export to Dynamic Path Monthly (1 Viewer)

Wapug

Registered User.
Local time
Yesterday, 22:23
Joined
Apr 14, 2017
Messages
51
At the end of every month I, or someone else now, need to export a query named qMonthEndMaintenanceData to an excel workbook with a tab named qMonthEndMaintenanceData. The Excel file is already located in a folder named for the previous month and workbook named for the month. I can do this in access by creating an export and just going in and updating the path, however, I would like to automate it for others, so they are not going into the database and monkeying with things. How can I set it so that a button on a form will open a browser to allow my user to browse to and select \\ShareDrive1\Tracking\April\AprilMonthEndData.xlsx or whatever location they wish?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:23
Joined
Oct 29, 2018
Messages
21,494
Hi. Maybe something like (for the current month):

"\\ShareDrive1\Tracking\" & Format(Date(),"mmmm") & "\" & Format(Date(),"mmmm") & "MonthEndData.xlsx"
 

Wapug

Registered User.
Local time
Yesterday, 22:23
Joined
Apr 14, 2017
Messages
51
Not sure I follow what you're saying here.
 

Isaac

Lifelong Learner
Local time
Yesterday, 19:23
Joined
Mar 14, 2017
Messages
8,778
Or, do a search for FileDialogue vba and check out that functionality.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:23
Joined
Oct 29, 2018
Messages
21,494
Not sure I follow what you're saying here.
Well, the way I understood your question was, you sort of wanted this path:

\\ShareDrive1\Tracking\April\AprilMonthEndData.xlsx

to become somewhat like this:

\\ShareDrive1\Tracking\NameOfMonth\NameOfFolderMonthEndData.xlsx

Did I misunderstand?
 

Cronk

Registered User.
Local time
Today, 12:23
Joined
Jul 4, 2013
Messages
2,772
Export your query to a fixed folder with a fixed name eg Folder: C:\temp, File: MonthEndData.xlsx.

Then have a line to store the new folder path as suggested by DBguy and create the folder

Code:
strFolder = "\\ShareDrive1\Tracking\" & Format(Date(),"mmmm")
mkdir strfolder

Then copy the file to the new folder and change its name
Code:
FileCopy "C:\temp\MonthEndData.xlsx",  strFolder & "\" & Format(Date(),"mmmm") & "MonthEndData.xlsx"

Then you'll have to use automation (look up how) to open the generated file in an instance of Excel and change the worksheet name.
Finally remove the temporary file using Kill to be ready for running the procedure next month.

BTW, what are you going to do April next year?
 

Users who are viewing this thread

Top Bottom