Referring to a path with a space

Novice1

Registered User.
Local time
Today, 02:49
Joined
Mar 9, 2004
Messages
385
I'm creating a report, saving it as a pdf, then later using the pdf as an attachment to an e-mail. Everything works fine. However, I've decided to save the pdf on the user's computer rather than save on a shared drive. The error I get is the Output To was cancelled. I believe it's because of the space in the path of the Output file. Does that sound right? If yes, can I use the path below? How would I change the code? Thanks

DoCmd.OpenReport "rptAssignmentRIP", acViewPreview, , , acHidden
DoCmd.OutputTo ObjectType:=acOutputReport, ObjectName:="rptAssignmentRIP", _
OutputFormat:=acFormatPDF, OutputFile:="C:\Users\Public\Public Documents\SignInPlus\CareerDevelopment\TempDocs\AssignmentRIP.pdf"
DoCmd.Close acReport, "rptAssignmentRIP"
 
Try

OutputFormat:=acFormatPDF, OutputFile:=””"C:\Users\Public\Public Documents\SignInPlus\CareerDevelopment\TempDocs\AssignmentRIP.pdf””"
DoCmd.Close acReport, "rptAssignmentRIP"

...if it works, then your idea about the space is correct.
 
I assume you mean the space in 'Public Documents' and not the one in 'As signmentRIP.pdf'

It would be much easier to remove the space(s) in the path or use an underscore instead.

Failing that, try any of these which MAY work though I'm doubtful:
a) putting the filepath in [] brackets
b) using a string variable strPath
Code:
strPath = "C:\Users\Public\Public Documents\SignInPlus\CareerDevelopment\TempDocs\AssignmentRIP.pdf"

DoCmd.OpenReport "rptAssignmentRIP", acViewPreview, , , acHidden
DoCmd.OutputTo ObjectType:=acOutputReport, ObjectName:="rptAssignmentRIP", _
OutputFormat:=acFormatPDF, OutputFile:=strPath
DoCmd.Close acReport, "rptAssignmentRIP"

c) use '%20' instead - that works in HTML but I've never tried it in this this type of code
Code:
C:\Users\Public\Public[COLOR="Red"]&20[/COLOR]Documents\SignInPlus\CareerDevelopment\TempDocs\AssignmentRIP.pdf

EDIT - just seen NG's suggestion - more likely to work methinks
 
When having a space becomes an issue, there is a tricky path to walk here. When an argument is passed to a sub, what typically happens is that one set of quotes is removed from the argument. Whatever parses the argument inside the thing that is called uses the space as a delimiter.

I have not seen it happen that often, but NG's suggesting regarding insertion of quotes (doubled because of quoted string rules for quotes inside of quotes) should be productive. But if that fails, you might try the two-step method. Create the file in the same folder as the database. Then use the FileSystemObject method to move the file to its final destination. I'm fairly sure that the FSO understands about spaces in paths.

Try NG's method FIRST. If it works, you don't NEED my extreme approach.

Another side note, though: From the command line, or from a Windows Explorer window, can you MANUALLY move a file to that destination? Because I could EASILY imagine that the OutputTo was cancelled for security permissions rather than syntax reasons.
 
The error I get is the Output To was cancelled. I believe it's because of the space in the path of the Output file. Does that sound right?
No, I'm afraid this doesn't sound right. Spaces in the path to OutputTo should not be an issue. There must be another cause for the error.
Double check if the target folder exists and if the user executing the code has permissions to write to it.
 
Just to confirm sonic8's reply, I've just tested your code deliberately saving a report to a PDF file where both the path & file name had spaces in. It works fine.
Check the path exists.

For info, notice how the browser displays the spaces in path & file name as '%20' as mentioned in my first reply

attachment.php
 

Attachments

  • Capture.PNG
    Capture.PNG
    56.7 KB · Views: 454
Last edited:
Double your backslash:

DoCmd.OpenReport "rptAssignmentRIP", acViewPreview, , , acHidden
DoCmd.OutputTo ObjectType:=acOutputReport, ObjectName:="rptAssignmentRIP", _
OutputFormat:=acFormatPDF, OutputFile:="C:\\Users\\Public\\Public Documents\\SignInPlus\\CareerDevelopment\\TempDocs\\AssignmentRIP.pdf"
DoCmd.Close acReport, "rptAssignmentRIP"
 
Actually, I think Sonic8 is on to something, especially since Ridders gave it a test on a known folder to which he had the appropriate permissions. Hopefully the OP will weigh in so we can hear the other shoe fall...
 

Users who are viewing this thread

Back
Top Bottom