-
I am having trouble launching applications using the "Shell" command in Access 97 when the file name contains spaces, it works great when there are no spaces. I tried putting the file name in quotes, brackets, parenthesis, single quotes, etc.- but no luck
e.g.
Shell pathname:=strDirectory & " " & strFile, windowstyle:=1
where strDirectory is the application for e.g. c\office\winword.exe
and
strFile is a file name with spaces e.g. "File With Spaces.doc"
-
It should work if you Contain the Path and File Name to the Document in Quotes, ie.
Code:
Shell sDir & " " & Chr(34) & sFile & Chr(34), vbNormalFocus
Alternatively you could use the GetShortPathName API to convert the Long File Name/Path into a Short 8.3 Format, ie.
Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Sub OpenWordFile(ByVal sFilename As String)
Dim sShort As String
sShort = Space(255)
Call GetShortPathName(sFilename, sShort, 255)
If InStr(sShort, Chr(0)) Then sShort = Left(sShort, InStr(sShort, Chr(0)) - 1)
Shell "C:\Office\WinWord.exe " & sShort, vbNormalFocus
End Sub
-
Thanks
Aaron Young-
thanks for your help!
I tried chr(34) & strFile & chr(34) earlier, but for some reason it did not work-when I thought it should. Your answer reaffirmed my faith in this fix so this time I reapplied it, then performed a little trick (for some reason Access every so often has a compile bug that requires you to delete your code- close the code view- then re-open and re-paste the exact code and for some reason it then works fine) that I haven't used in a while, and it then worked as expected.
thanks-it was driving me crazy
allan