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

File name with spaces in Call Shell function 2

Status
Not open for further replies.

lynns

Technical User
Mar 1, 2000
9
US
I am trying to use an Access application as a sort of menu system. The user selects the file from a combo box. The columns in the combo box then furnish the program needed to open the file, the file path, the file name and the file extension.

This works pretty well until I run acrose a file name with a space in it. Sample code and values provided are shown below

Dim stAppName As String
Dim ProgramName As String
Dim FileLocation As String
Dim FileName As String
Dim FileExtension As String

ProgramName = "C:\Program Files\Microsoft Office\Office\msaccess.exe "
FileLocation = "\\Hlkoas01\Dover2\Warranty\Pjob costs\"
FileName = "pjob cost"
FileExtension = ".mdb"

stAppName = ProgramName & FileLocation & FileName & FileExtension

The routine submits the following string for the variable stAppName

C:\Program Files\Microsoft Office\Office\msaccess.exe \\Hlkoas01\Dover2\Warranty\Pjob costs\pjob cost.mdb

Call Shell(stAppName, 1)

This command tries to open \\Hlkoas01\Dover2\Warranty\Pjob.mdb which does not exist.

Any ideas how to resolve the space problem? I can not rename the file or directory as it does not "belong" to me.

Thanks

LynnS
 
try including single quotes around your variable....

stAppName = ProgramName & FileLocation & "'" & FileName & "'" & FileExtension

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
You actually need to get some double quotes INTO the string that goes to the Call Shell()

So use
Code:
stAppName = ProgramName & """" & FileLocation & FileName & FileExtension & """"

In that way the string variable stAppName will be

C:\Program Files\Microsoft Office\Office\msaccess.exe "\\Hlkoas01\Dover2\Warranty\Pjob costs\pjob cost.mdb"


And that will work fine.

Then write out 100 times
"I must not use spaces in object names - EVER."




G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top