.ActiveDocument.SaveAs

lukekelly

Registered User.
Local time
Today, 20:10
Joined
Jan 18, 2010
Messages
33
Hi all,

having a problem getting my .ActiveDocument.SaveAs code to create a new folder as well as saving the document. It works fine if its saved into a folder that already exists but just generates and doesnt save when i try and specify a new folder based on a filed name in the form.

My current working code:

Code:
.ActiveDocument.SaveAs FileName:="Y:\CPAMS\Quotes\" & "Q" & Format((Forms![frm_quote]![ID]), "#-00000") & " - " & Forms![frm_quote]![ProjTitle] & ".doc"

And the code ive just tried:

Code:
.ActiveDocument.SaveAs FileName:="Y:\CPAMS\Quotes\" & Format((Forms![frm_quote]![ID]), "#-00000") & "\" & "Q" & Format((Forms![frm_quote]![ID]), "#-00000") & " - " & Forms![frm_quote]![ProjTitle] & ".doc"

Any pointers greatly appreciated

Thanks

Luke
 
Create the directory if it does not exist using the MKDir function.

Code:
dim sDirectoryPath as string
sDirectoryPath = "C:\Test\"

If Dir(sDirectoryPath, vbDirectory)= "" then MkDir sDirectoryPath

Search the forum for there are lots of code examples already posted.
 
Hi thanks for the reply ghudson,

Yes I had taken a look at the forums for MKDir, have used the function previously, but wasnt sure howid use it in this context:

Code:
Dim sDirectoryPath As String

sDirectoryPath = "Y:\CPAMS\Quotes\" & "Q" & Format((Forms![frm_quote]![ID]), "#-00000")

If Dir(sDirectoryPath, vbDirectory) = "" Then MkDir sDirectoryPath

.ActiveDocument.SaveAs FileName:="Y:\CPAMS\Quotes\" & "Q" & Format((Forms![frm_quote]![ID]), "#-00000") & " - " & Forms![frm_quote]![ProjTitle] & ".doc"

because I want to save the document in the newly created folder Im not sure how to direct it in the new folder, I could make it easier for me and create another button to create the folder first, but would like it to all happen in the same code for the user. So im kinda in the same position as when I started.

Obviously I have to change something in the saveas Filename part, have tried a few things but not getting anywhere, the document is just producing in the parent folder and not the new sub folder, although that is being created.

Any further pointers appreciated, Thanks

Luke
 

Users who are viewing this thread

Back
Top Bottom