Having trouble with OutputTo file path (1 Viewer)

thardyjackson

Registered User.
Local time
Yesterday, 20:44
Joined
May 27, 2013
Messages
45
I am trying to export a table with VBA. This code works fine:

Code:
DoCmd.OutputTo acOutputQuery, objectName, "ExcelWorkbook(*.xlsx)", "TESTFILE.xlsx"

The code below (with a path) does NOT work. The only difference is the path prefix. I have tried different paths with no success. The error is run time 2302 "Microsoft Access can't save the output data to the file you've specified."

Code:
DoCmd.OutputTo acOutputQuery, objectName, "ExcelWorkbook(*.xlsx)", "C:\TESTFILE.xlsx"

Any ideas?
 

AdamCLloyd

New member
Local time
Today, 04:44
Joined
Jul 5, 2013
Messages
8
Hi there thardyjackson,

I could only replicate this error when I did not have privileges to the folder I was trying to create the file on.

I logged onto a domain, which blocks direct files onto C:/ and replicated the error you got. I then created a subfolder on the C:/ called BLAH, and obviously then had access to this C:/BLAH Folder to create files and the code worked fine.

Also, if you want access to open the file after its exported, you can do a hyperlink follow line like below.

Code:
DoCmd.OutputTo acOutputQuery, "qryMonths", "ExcelWorkbook(*.xlsx)", "C:\BLAH\TESTFILE.xlsx"
Application.FollowHyperlink "C:\BLAH\TESTFILE.xlsx"
 

thardyjackson

Registered User.
Local time
Yesterday, 20:44
Joined
May 27, 2013
Messages
45
That was the issue. Thanks.
 

Users who are viewing this thread

Top Bottom