General discussion

Locked

FileName for OutputTo action

By dennisbv ·
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. "

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

FileName for OutputTo action

by SteveD In reply to FileName for OutputTo act ...

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

Collapse -

FileName for OutputTo action

by Shanghai Sam In reply to FileName for OutputTo act ...

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"

Collapse -

FileName for OutputTo action

by dennisbv In reply to FileName for OutputTo act ...

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"

Collapse -

FileName for OutputTo action

by SteveD In reply to FileName for OutputTo act ...

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.

Collapse -

FileName for OutputTo action

by dennisbv In reply to FileName for OutputTo act ...

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.

Collapse -

FileName for OutputTo action

by dennisbv In reply to FileName for OutputTo act ...

This question was closed by the author

Back to Software Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums