30. juni 2003 - 19:01Der er
11 kommentarer og 1 løsning
shellexec i access97
Hej
Det er lykkedes mig at få en ShellExecute til at virke i Access2000, men når jeg kompilerer tilbage til Access97 (hvor den skal benyttes), for jeg fejlen "ventede ID" pga. en Public Enum (vist nedenfor).
Håber der er nogen der ved om man kan få access97 til at forstå ovenstående, eller kender en anden smart måde at åbne en fil via dialogbox (uden brug af ENUM)?
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
and if it ius actually the shellexec you are using then this is an example which work in 97 too. This example opens a jpg file using the associated program.
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const SW_HIDE = 0 Public Const SW_SHOW = 5
Private Sub Command1_Click() Dim stAppPath As String Dim stAppName As String Dim result As Integer
On Error GoTo Err_Command1_Click
stAppName = "My.jpg" stAppPath = "D:\"
result = ShellExecute(0, "Open", stAppName, "", stAppPath, SW_SHOW)
If result < 32 Then MsgBox "Couldn't open file ..." End If
Hi terry Thanks for fast reply! I tried the public const method instead of the ENUM - but without succes. Instead I followed your suggestion with Call the standard Windows File Open/Save dialog box. THIS WORKS - but just returns the filename that I pick - how do I open this file, when I have the name!!????
can we see your code? I am still a little puzzled as to what your actually trying to do! When you say "how do I open the file" are you trying toopen it using the associated program? If so then the example above 20:49:13 should work!
Hi again Here is the original code that works in 2000 but not in 97 (even after replacing ENUM with public function): Option Compare Database Option Explicit
Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _ (ByVal hWnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, _ ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function ShellExecuteForExplore Lib "Shell32.dll" _ Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As Any, lpDirectory As Any, ByVal nShowCmd As Long) As Long
Public Function ShellEx( _ ByVal sFIle As String, _ Optional ByVal eShowCmd As EShellShowConstants = essSW_SHOWDEFAULT, _ Optional ByVal sParameters As String = "", _ Optional ByVal sDefaultDir As String = "", _ Optional sOperation As String = "open", _ Optional Owner As Long = 0 _ ) As Boolean Dim lR As Long Dim lErr As Long, sErr As Long If (InStr(UCase$(sFIle), ".EXE") <> 0) Then eShowCmd = 0 End If On Error Resume Next If (sParameters = "") And (sDefaultDir = "") Then lR = ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_SHOWNORMAL) Else lR = ShellExecute(Owner, sOperation, sFIle, sParameters, sDefaultDir, eShowCmd) End If If (lR < 0) Or (lR > 32) Then ShellEx = True Else ' raise an appropriate error: lErr = vbObjectError + 1048 + lR Select Case lR Case 0 lErr = 7: sErr = "Out of memory" Case ERROR_FILE_NOT_FOUND lErr = 53: sErr = "File not found" Case ERROR_PATH_NOT_FOUND lErr = 76: sErr = "Path not found" Case ERROR_BAD_FORMAT sErr = "The executable file is invalid or corrupt" Case SE_ERR_ACCESSDENIED lErr = 75: sErr = "Path/file access error" Case SE_ERR_ASSOCINCOMPLETE sErr = "This file type does not have a valid file association." Case SE_ERR_DDEBUSY lErr = 285: sErr = "The file could not be opened because the target application is busy. Please try again in a moment." Case SE_ERR_DDEFAIL lErr = 285: sErr = "The file could not be opened because the DDE transaction failed. Please try again in a moment." Case SE_ERR_DDETIMEOUT lErr = 286: sErr = "The file could not be opened due to time out. Please try again in a moment." Case SE_ERR_DLLNOTFOUND lErr = 48: sErr = "The specified dynamic-link library was not found." Case SE_ERR_FNF lErr = 53: sErr = "File not found" Case SE_ERR_NOASSOC sErr = "No application is associated with this file type." Case SE_ERR_OOM lErr = 7: sErr = "Out of memory" Case SE_ERR_PNF lErr = 76: sErr = "Path not found" Case SE_ERR_SHARE lErr = 75: sErr = "A sharing violation occurred." Case Else sErr = "An error occurred occurred whilst trying to open or print the selected file." End Select
Err.Raise lErr, , App.EXEName & ".GShell", sErr ShellEx = False End If
I forgot to tell you that the error i get compiling is this (after using public const instead of ENUM):
User defined type not defined: Public Function ShellEx( _ ByVal sFIle As String, _ Optional ByVal eShowCmd As EShellShowConstants = SW_SHOWDEFAULT, _ Optional ByVal sParameters As String = "", _ Optional ByVal sDefaultDir As String = "", _ Optional sOperation As String = "open", _ Optional Owner As Long = 0 _ ) As Boolean
Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _ (ByVal hWnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, _ ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function ShellExecuteForExplore Lib "Shell32.dll" _ Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As Any, lpDirectory As Any, ByVal nShowCmd As Long) As Long
Public Const SW_HIDE = 0 Public Const SW_MAXIMIZE = 3 Public Const SW_MINIMIZE = 6 Public Const SW_SHOWMAXIMIZED = 3 Public Const SW_SHOWMINIMIZED = 2 Public Const SW_SHOWNORMAL = 1 Public Const SW_SHOWNOACTIVATE = 4 Public Const SW_SHOWNA = 8 Public Const SW_SHOWMINNOACTIVE = 7 Public Const SW_SHOWDEFAULT = 10 Public Const SW_RESTORE = 9 Public Const SW_SHOW = 5
Public Function ShellEx( _ ByVal sFIle As String, _ Optional ByVal eShowCmd As Integer = SW_SHOWDEFAULT, _ Optional ByVal sParameters As String = "", _ Optional ByVal sDefaultDir As String = "", _ Optional sOperation As String = "open", _ Optional Owner As Long = 0 _ ) As Boolean Dim lR As Long Dim lErr As Long, sErr As Long
If (InStr(UCase$(sFIle), ".EXE") <> 0) Then eShowCmd = 0 End If On Error Resume Next If (sParameters = "") And (sDefaultDir = "") Then lR = ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, SW_SHOWNORMAL) Else lR = ShellExecute(Owner, sOperation, sFIle, sParameters, sDefaultDir, eShowCmd) End If
If (lR < 0) Or (lR > 32) Then ShellEx = True Else ' raise an appropriate error: lErr = vbObjectError + 1048 + lR Select Case lR Case 0 lErr = 7: sErr = "Out of memory" Case ERROR_FILE_NOT_FOUND lErr = 53: sErr = "File not found" Case ERROR_PATH_NOT_FOUND lErr = 76: sErr = "Path not found" Case ERROR_BAD_FORMAT sErr = "The executable file is invalid or corrupt" Case SE_ERR_ACCESSDENIED lErr = 75: sErr = "Path/file access error" Case SE_ERR_ASSOCINCOMPLETE sErr = "This file type does not have a valid file association." Case SE_ERR_DDEBUSY lErr = 285: sErr = "The file could not be opened because the target application is busy. Please try again in a moment." Case SE_ERR_DDEFAIL lErr = 285: sErr = "The file could not be opened because the DDE transaction failed. Please try again in a moment." Case SE_ERR_DDETIMEOUT lErr = 286: sErr = "The file could not be opened due to time out. Please try again in a moment." Case SE_ERR_DLLNOTFOUND lErr = 48: sErr = "The specified dynamic-link library was not found." Case SE_ERR_FNF lErr = 53: sErr = "File not found" Case SE_ERR_NOASSOC sErr = "No application is associated with this file type." Case SE_ERR_OOM lErr = 7: sErr = "Out of memory" Case SE_ERR_PNF lErr = 76: sErr = "Path not found" Case SE_ERR_SHARE lErr = 75: sErr = "A sharing violation occurred." Case Else sErr = "An error occurred occurred whilst trying to open or print the selected file." End Select
Err.Raise lErr, , App.EXEName & ".GShell", sErr ShellEx = False End If
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.