Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011

    Unanswered: ShellExecute with Wildcard

    I was wondering if I could use a wildcard (*) in a ShellExecute. I'm trying to get a button to open a pdf file located in a certain directory but the description of the file is always different hince the wildcard. Here's my code.

    Private Sub Command110_Click()
    Dim RetVal As Long
    Dim TaskID As Variant
    Dim FullFilePath As String
    Dim strFileName As String
    On Error Resume Next
    If Not IsNull(Me.Document) Then
    FullFilePath = "G:\Finance\Leases\Scanned Leases\" & [Me.PropertyID] & "*.pdf"
    RetVal = apiShellExecute(hWndAccessApp, "open", FullFilePath, vbNullString, vbNullString, vbNormalFocus)
    If RetVal = 0 Then '0 indicates not enough memory
    MsgBox "The operating system is out of memory or resources.", vbExclamation, "File Open Failure"
    ElseIf RetVal = 2 Then '2 indicates that the file was not found
    MsgBox "The specified file was not found.", vbExclamation, "File Open Failure"
    ElseIf RetVal = 3 Then '3 indicates that the path was not found
    MsgBox "The specified path was not found.", vbExclamation, "File Open Failure"
    ElseIf RetVal = 11 Then '11 indicates that the executable is corrupted
    MsgBox "The .exe file is invalid (non-Win32 .exe or error in .exe image).", vbExclamation, "File Open Failure"
    ElseIf RetVal = 31 Then 'If the association is missing, then use Shell to try the OpenWith dialog
    TaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & FullFilePath, vbNormalFocus)
    ElseIf RetVal <= 32 Then 'the apishellexecute function returns a value greater than 32 on success
    MsgBox "File could not be opened. Error number " & CStr(RetVal), vbExclamation, "File Open Failure"
    End If
    MsgBox "No file location entered!", vbExclamation, "Can not open file"
    End If
    End Sub
    This actually just opens up My Documents for some reason. If I take out
     &[Me.PropertyID] & "*.pdf"
    the button takes me to the right folder but I need to pull the actual pdf file. Any help would be greatly appreciated.

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 14
    Whatever the method you use can be, you cannot open a file if you don't know its name.

    See also: ShellExecute function
    Have a nice day!

Posting Permissions

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