Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using double quotes for a long path

Status
Not open for further replies.

Jonath

Technical User
Jul 13, 2007
27
FR
Hi,

I have a form with a button that allows editing and saving a Word document.

However the folder where I want to save the document is quite long and I'm having an error at this line:

Code:
fichier.activedocument.saveas ("c:\Documents and settings\eric\mes documents\Objectif Terrain\Acomptes\Acompte " & CStr(Forms![enqueteur]![Name1]) & " " & CStr(Forms![enqueteur]![Name2]) & ".doc")
[code]

I tried various combinations using "" instead of ", or ' instead of ", in vain.

Any help is very appreciated
Thanks in advance

Jonath.
 
Assuming that c:\Documents and settings\eric\mes documents\Objectif Terrain\Acomptes\ is the bottom most folder, this will help track down what's happening:

Code:
Dim strPath As String

strPath = "c:\Documents and settings\eric\mes documents\Objectif Terrain\Acomptes\Acompte " 

strPath = strPath & CStr(Forms![enqueteur]![Name1]) & " " & CStr(Forms![enqueteur]![Name2]) & ".doc"

fichier.activedocument.saveas strPath

Breaking your code down to this, If you put an MsgBox line immediately above the last line:

MsgBox strPath

what comes up?

John
 
What was the error?

I always think it is bad practice to have spaces in filenames and paths. Where you have spaces above try using underscores instead:

Code:
fichier.activedocument.saveas ("c:\Documents and settings\eric\mes_documents\Objectif_Terrain\Acomptes\Acompte_" & CStr(Forms![enqueteur]![Name1]) & "_" & CStr(Forms![enqueteur]![Name2]) & ".doc")

Jason
 
How are ya Jonath . . .

. . . and this:
Code:
[blue]   Dim DQ as String

   DQ=""""

   fichier.activedocument.saveas ([purple][b]DQ[/b][/purple] & "c:\Documents and settings\eric\mes documents\Objectif Terrain\Acomptes\Acompte " &    CStr(Forms![enqueteur]![Name1]) & " " & CStr(Forms![enqueteur]![Name2]) & ".doc" & [purple][b]DQ[/b][/purple][/blue]

Use Debug.Print to see exactly where its failing . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Hi [blue]jrbarnett[/blue],

I tried your suggestion with strpath:

- the msgbox displays the correct folder/file name!!
- BUT it won't save the file ("invalid file name") :-/

Thanks anyway, I'm gonna try djayam's idea.

Jonath.
 
Hi [blue]djayam[/blue],

thanks for your reply, but using underscores didn't make it.
I still have error 5152 "invalid file name", even if I use underscores for every folder name (c:\documents_and_settings\....), which would be very unlikely by the way :p

Jonath.
 
Hi [blue]TheAceman1[/blue],

I tried your syntax, but it still lead me to the same error.

How is "Debug.print" supposed to work ?!
Access Help tells me it displays text in the execution window,
but I didn't get anything there.

Thanks anyway, I'm still open to any suggestion
 
Try creating a simple folder eg c:\test\ and saving there. If that works it's your folder location that's the problem, if not replace your variables with a set name eg test.doc and try again. If that works there must be an invalid character in your docname strings?
 
I'm sure the problem comes from the long path.

I can save the file in a simple folder such as c:\documents and settings\jonath\my documents\file.doc

I read that Access can't deal with paths including lots of spaces :-/

I'm looking at now...

any help is welcome :-D
 
Can you post some examples of what is in the Name1 and Name2 controls on your form please?

Just want to check there's no characters in there that aren't valid in filenames (eg brackets, ? @, comma, asterisk, \ / ).

The debug.print statement mentioned by AceMan1 will display the statement on the debug window as the program runs. Press Ctrl G to open it if not shown (its at the bottom of the vba editor by default).

John
 
Examples of the fields:

Name1: Name2:
STINGRE WILLIAM
PROHET NATHALIE
MARQUET ESTELLE

I don't think there is any problem with the fields; they are just names with capital letters and no "forbidden" characters.

I can save the file as [bold]c:\Documents and settings\eric\my documents\objectif terrain\Acompte STINGRE WILLIAM.doc[/bold]

[bold]BUT[/bold] I can't if I add one more folder, eg: [bold]c:\Documents and settings\eric\my documents\objectif terrain\acomptes\acompte STINGRE WILLIAM.doc[/bold]


I read that I must use double quotes eg " ""c:\documents..."" " but it becomes messy with the & and Forms![...] ; I couldn't find the right syntax...yet?

Thanks for your help, I'm getting real stuck here :-/
 
Oh my...!

The folder where I want to save the files must be CREATED MANUALLY before using ACCESS !!!!

I can't believe I didn't try that sooner :)

Thanks all for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top