Shell statement returns error 5 "Invalid procedure call or argument"

Hello all

The following lines return an "Invalid procedure call or argument" runtime error #5, and I have no idea why:

sShellPath = chr(34) & "c:\Windows\Notepad.exe " & sDestinationPath & chr(34)
dbl = Shell(sShellPath, vbMaximizedFocus)

sDestinationPath is a valid path/file, sShellPath is a string, Notepad is at the above path, and dbl is a double.  

I also tried this referencing Wordpad, and the file at sDestinationPath is not read-only.

I'm using Windows XP SP2/Access XP.

Thanks in advance.
LVL 66
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAsked:
Who is Participating?
Hey Jim!

Use this mate.

sShellPath = "Notepad.exe " & Chr(34) & sDestinationPath & Chr(34)
dbl = Shell(sShellPath, vbMaximizedFocus)

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
Worked like a charm.  'Spanks...  -Jim
You just had the " (chr(34)'s) in the wrong spot

Also, you dont need to pass the win dorectory to it either... You may have had issues if you moved your app to a different V of Windows (Win2K = c:\winnt\)

Take care mate!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.