Discussion Locked

FileName for OutputTo action

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I asked a question about creating a Excel file from Access, The answer I accepted was the Outputto function in Access. What I need to know is can I create a new file with a Name from a stirng in my code. The OutputTo Action works if I put the nameof an Existing File I cannot seem to create a new file.
Here is my syntax
DoCmd.OutputTo acOutputQuery, "qryReport", acFormatXLS, " rptTest.xls", True

I tryed to put in strFileName(the file name I want)in place of rptTest.xls but I recieve the message "Run-Time Error '2302':
Kohlerdatabase can't save the output data to the file you've selected. "

6 replies

by steved

Did you put strFileName in place of rptText.xls or strFileName in place of "rptText.xls"? In other words, did you get rid of the quotes? If so, did you check to make sure that the strFileName variable really contains the value you're expecting?

Forgive me if these are too simple. They're the first debugging possibilities that come mind. I hope this helps.

Steve Diamond

by shanghai sam

I am sorry that I have reject this answer to post my reply

This is the syntax I use strFile name is a string I create by adding the Begin and End dates and the time to the file path.
DoCmd.OutputTo acOutputQuery, "qryReport", acFormatXLS, strFileName, True

I use a MsgBox to see what the srtFilename variable holds
the variable is
C:\winnt\profiles\Administrator.001\Desktop\Kohler report program\3/1/01 To 4/30/01-1:54:55 PM Report.xls

This is the Begin & End Date & Time & Report.xls

"3/1/01 To 4/30/01-1:54:55 PM Report.xls"

by dennisbv

This is the syntax I use strFile name is a string I create by adding the Begin and End dates and the time to the file path.
DoCmd.OutputTo acOutputQuery, "qryReport", acFormatXLS, strFileName, True

I use a MsgBox to see what the srtFilename variable holds
the variable is
C:\winnt\profiles\Administrator.001\Desktop\Kohler report program\3/1/01 To 4/30/01-1:54:55 PM Report.xls

This is the Begin & End Date & Time & Report.xls

"3/1/01 To 4/30/01-1:54:55 PM Report.xls"

by steved

The problem is that your filename is not valid under Windows filesystem naming rules, which do not permit any of these characters

\/:*?"<>|

in filenames. You'll have to replace the slashes in your dates and the colons in your times with characters that are legal.

by dennisbv

Thanks your answer was a great help. I formated the dates before I strung them together. So I get the name "Mar 1 To Apr 30 2001 - Report.xls". Which gives be the name I needed.

This discussion is closed to new replies.