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

Posted on 2004-10-25
Last Modified: 2008-02-01
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.
Question by:Jim Horn
    LVL 34

    Accepted Solution

    Hey Jim!

    Use this mate.

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

    LVL 64

    Author Comment

    by:Jim Horn
    Worked like a charm.  'Spanks...  -Jim
    LVL 34

    Expert Comment

    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!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now