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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA balking at spaces in code

Status
Not open for further replies.

evansc

Technical User
Joined
Jul 19, 2004
Messages
42
Location
US
I'm running code in Access that is supposed to open a document in Word for a mail merge. The problem is, I get an error saying the path is not valid. Upon testing and researching this, I have discovered the problem is the spaces--it only reads this much of the path correctly: "\\documents\Offices\Judicial"

Someone suggested "MapPath"--but I am unfamiliar with that because I am only a beginner with VBA. (I'm good at copying and pasting what other people suggest though! :) ) Could someone look at the following code and give me ideas that might work?


Dim myQuery As String
Dim myPath As String

myPath = myPath = "\\documents\Offices\Judicial & Court Services\Judicial College\Shared Project Folders\Templates\Letters & Accessories\MailMergeTemplates\Conf Letter Mail Merge.doc"
myQuery = "qryMakeTempTable"

DoCmd.SetWarnings (WarningsOff)
DoCmd.OpenQuery (myQuery)

Dim MyDoc
MyDoc = Shell("C:\Program Files\Microsoft Office\Office10\WINWORD.EXE " & myPath, 1)

DoCmd.SetWarnings (WarningsOn)
DoCmd.Quit acSave
DoCmd.Close , ""

End Sub
 
Try changing this...
myPath = myPath = "\\documents\Offices..."

to this...
myPath = "\\documents\Offices..."

and this...
MyDoc = Shell("C:\Program Files\Microsoft Office\Office10\WINWORD.EXE " & myPath, 1)

to this...
Shell("C:\Program Files\Microsoft Office\Office10\WINWORD.EXE " & myPath, 1)


Randy
 
oops--the My Path twice was a typo. Fixed it. Thanks!

But when I made the other change, I get a message saying "Expect =".
 
Someone on another forum got me an answer!!!

I put double quotes around the path name--like follows:
"""\\documents\Offices\Judicial & Court Services\Judicial College\Shared Project Folders\Templates\Letters & Accessories\Conf Letter Mail Merge.doc"""

Thought someone might want to know!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top