Results 1 to 5 of 5

Thread: Shell in VBA

  1. #1

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    Shell in VBA

    I use this code to open a txt file in access:
    VB Code:
    1. Private Sub cmdViewFile_Click()
    2. Dim retval As Variant
    3. Dim strpath As String
    4. strpath = "c:\logfile.txt"
    5. retval = Shell("C:\winnt\system32\notepad.exe" & " """ & strpath & """", vbNormalFocus)
    6. End Sub
    I will be giving some co-workers access to this db and not everyone has NT so the path of Notepad will be different.

    What I have done is created a field for FilePath that holds the path of the associated file. I would like to code the button to use that field as the full path and when clicked use the systems default viewer to open it.

    I use this in my vb app;

    VB Code:
    1. ShellExecute Me.hwnd, vbNullString, File1.path & "\" & sName, vbNullString, "c:\", SW_SHOWNORMAL
    But I am new to VBA!
    P.S. I have searched this forum and the access forums I use but something similar to what I already have is all I've gotten.


    I hope I was clear and I hope someone can help!?!

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    I would personally just send notepad.exe with your app.

  3. #3
    jim mcnamara
    Guest
    I'm confused - ShellExecuteEx works in VBA, and it knows what executable to open - the associated one for the file type.

    What is it that I'm missing here?

  4. #4
    jim mcnamara
    Guest
    Or are your trying to find the system folder?

    Find the system fiolder

    Code:
    Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim sSave As String, Ret As Long
        'Create a buffer
        sSave = Space(255)
        'Get the system directory
        Ret = GetSystemDirectory(sSave, 255)
        'Remove all unnecessary chr$(0)'s
        sSave = Left$(sSave, Ret)
        'Show the windows directory
        MsgBox "Windows System directory: " + sSave
    End Sub

  5. #5

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    The error I get wth ShellExecuteEx is:

    "The file does not have a program associated with it for performing this action. Create an association in the Folder Options control panel."

    I've done that, I've even tried other file types in various directories and still nothing.

    Oh well....

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width