1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Access 2003 - Correct Use of VBA "Shell" command

Discussion in 'Business Applications' started by Chris_E, Jun 9, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. Chris_E

    Chris_E Thread Starter

    Joined:
    Feb 16, 2006
    Messages:
    360
    In my VBA script, I have a section associated with an onclick event in my Access form. Onclick, I want to run Adobe Acrobat and open a specific PDF file.

    Now I have this code (paths for 'Filename' is an example)

    Dim RetVal
    Dim Filename As String

    Filename = "C:\ManualRevA.pdf"

    RetVal = Shell("C:\Program Files\Adobe\Adobe Acrobat 6.0\Acrobat\acrobat.exe " & Filename, 1)


    This is ok for the filename as I'll be using InstallShield to fix the location of the PDF. The problem arises with the path for Acrobat itself. If the client is running version 6 or 7, the text for the path is different.

    I saw a reference to on a different website to the start command (which works at the DOS level)

    Shell "start C:\ManualRevA.pdf"

    This would allow the VBA to call up the PDF without the acrobat.exe element, it uses the file type to determine the correct application.

    Trouble is I can't figure the syntax for the "Shell start... " command so its not working for me and I'd like it to!

    Can anyone help?

    Thx in advance

    Chris
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,732
    What don't you just use an IF / ELSE statement to determine which path to use depending on whether the Adobe 6.0 directory exists?

    Rollin
     
  3. cristobal03

    cristobal03

    Joined:
    Aug 5, 2005
    Messages:
    3,072
    In the command prompt, you can type start /? for more usage information. It looks like what you have there is correct. However, you'll have some major problems if there are any spaces in the filename. What sort of behavior are you seeing at the moment?

    chris.
     
  4. Ivan F Moala

    Ivan F Moala

    Joined:
    Dec 26, 2004
    Messages:
    5
    you can also lauch it via Rundll

    Sub LaunchApp()
    '// Windows 2000,Windows XP,Windows 2003
    '// Launch any registered application (.exe, .doc, etc).

    Shell "RunDLL32.EXE shell32.dll,ShellExec_RunDLL C:\ExcelFiles\match-schedule-wm-2006,property=publicationFile.pdf "


    End Sub
     
  5. GTAdoum

    GTAdoum

    Joined:
    Apr 29, 2008
    Messages:
    1
    Shell "cmd.exe /c Start ""Window title"" ""path to file\file.ext""", vbHide

    Double quotes to pass as a single quote, in case of spaces...
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/473952