View Full Version : DoCmd.OutputTo Create folder if it doesn't already exist


flemmo
12-29-2008, 03:48 AM
Hi,

I have a button that exports a report to RFT (then opens it) as follows:

DoCmd.OutputTo acReport, "QuotationRevisions", acFormatRTF, "C:\Reports\" & Year(Now()) & "\Report.rtf", -1

So if the button were to be clicked today (29/12/2008) the report would be saved to:
C:\Reports\2008\Report.rtf

However, if the folder "2008" isn't already created, the file wont save. I want it to automatically create a "2008" folder if it doesn't already exist. Is this possible?

Thanks

pbaldy
12-29-2008, 06:58 AM
You can test for its existence with the Dir() function, and create it if it doesn't exist.

namliam
12-29-2008, 07:02 AM
Search for "File system object" or "Filesystemobject" if you need to find out how to create the folder.

flemmo
12-29-2008, 07:07 AM
The FSO method worked a treat, thank you.
I used the following page to learn how, for anyone else trying to do the same:

http://www.microsoft.com/technet/scriptcenter/resources/begin/ss0507.mspx