Hi Colin
Thank you again for your reply. I'm sorry but I don't quite follow all of your suggestions. I will admit that I am a bit (maybe a lot) out of my depth here, but I'm willing to keep plugging away. Again, I really appreciate your help.
In your corrected code, unless I am mistaken, you seem to have duplicated the Declare PtrSafe Function
Code:
#If VBA7 Then 'A2010 or later (32/64-bit)
Private Declare PtrSafe Function Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
Declare PtrSafe Function GetDesktopWindow Lib "User32" () As LongPtr
#Else 'A2007 or earlier
Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
#End If
The code below will run correctly, however if I comment out my lines of code, and remove the comments from your code, I recieve a Type mismatch error on this line with ShellExecute highlighted;
StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:", SW_SHOWNORMAL)
Code:
Option Compare Database
Option Explicit
#If VBA7 Then 'A2010 or later (32/64-bit)
'Declare PtrSafe Function LaunchApp Lib "User32" (ByVal n As LongLong) As Long
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Declare PtrSafe Function GetDesktopWindow Lib "User32" () As Long
#Else 'A2007 or earlier
Private Declare Function GetDesktopWindow Lib "User32" () As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
#End If
'#If VBA7 Then 'A2010 or later (32/64-bit)
' Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
' Declare PtrSafe Function GetDesktopWindow Lib "User32" () As LongPtr
'#Else 'A2007 or earlier
' Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
' Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
'#End If
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&
Public Sub OpenNativeApp(ByVal psDocName As String)
Dim r As Long, Msg As String
r = StartDoc(psDocName)
If r <= 32 Then
'There was an error
Select Case r
Case SE_ERR_FNF
Msg = "File not found"
Case SE_ERR_PNF
Msg = "Path not found"
Case SE_ERR_ACCESSDENIED
Msg = "Access denied"
Case SE_ERR_OOM
Msg = "Out of memory"
Case SE_ERR_DLLNOTFOUND
Msg = "DLL not found"
Case SE_ERR_SHARE
Msg = "A sharing violation occurred"
Case SE_ERR_ASSOCINCOMPLETE
Msg = "Incomplete or invalid file association"
Case SE_ERR_DDETIMEOUT
Msg = "DDE Time out"
Case SE_ERR_DDEFAIL
Msg = "DDE transaction failed"
Case SE_ERR_DDEBUSY
Msg = "DDE busy"
Case SE_ERR_NOASSOC
Msg = "No association for file extension"
Case ERROR_BAD_FORMAT
Msg = "Invalid EXE file or error in EXE image"
Case Else
Msg = "Unknown error"
End Select
MsgBox Msg
End If
End Sub
Private Function StartDoc(psDocName As String) As Long
Dim Scr_hDC As Long
'#If VBA7 Then
' Dim Scr_hDC As LongPtr
'#Else
' Dim Scr_hDC As Long
'#End If
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
End Function
For reference, the routine is executed from a command button on a form;
Code:
Private Sub GoogleMapsBtn_Click()
Dim stGoogleMap As String
Dim stURL As String
On Error GoTo Err_GoogleMapsBtn_Click
stGoogleMap = "http://maps.google.com/maps?q="
stURL = stGoogleMap & [Address] & " " & [City] & " " & [PostalCode]
Exit_GoogleMapsBtn_Click:
Exit Sub
Err_GoogleMapsBtn_Click:
MsgBox "An unexpected error has prevented this function from launching.", vbCritical + vbOKOnly, "Mapping Error"
Resume Exit_GoogleMapsBtn_Click
End Sub