Can't shell out to open a document listed on a form - has comma in name

M

M Skabialka

I have an Access 2003 form that lists documents and their path using a
listbox. Users can select these and double-click to open them.
Except that I found some documents with commas in their name. The command I
use is:
Call Shell("Explorer.exe " & txtFilePath, vbNormalFocus) which contains info
like this:
Call Shell("Explorer.exe G:\Resumes\Smith, Jones 12/12/07", vbNormalFocus)
which gives an error, and seems to select the text after the comma for this
message:
The path 'Jones 12/12/07' does not exist or is not a directory
The file does not open.

If I put
G:\Resumes\Smith, Jones 12/12/07
in an Explorer Window it opens the document, so I don't think Windows XP is
the problem.

How can I resolve this in trying to open these docs from Access (there are
too many with commas to ignore or rename).
Thanks,
Mich
 
K

Klatuu

It is not just the commas, it will fail with just spaces in the name. The
cure it to enclose the passed value in quotes:
Call Shell("Explorer.exe """ & txtfilepath & """", vbNormalFocus)
 
M

M Skabialka

I finally got it working by adding Chr(34) at each end of the string -
spaces were no problem.
Call Shell("Explorer.exe " & Chr(34) & txtfilepath & Chr(34), vbNormalFocus)
Thanks anyway!
Mich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top