Reputation: 23
I have used the "Shell" function, in other Access databases, to open folders.
With the same code structure I get the
5 error code of "Invalid procedure call or argument"
Using shell function as follows:
Dim FreightFile_Path As String
FreightFile_Path = "S:\Supply Chain\Freight"
Shell "explorer.exe" & " " & FreightFile_Path, vbNormalFocus
I tried the double quotes and Chr(34)'s around them.
I copied the code from one database (that it worked in) to another and it error-ed.
Am I missing something I need to activate in MS Access? I checked the references in VBA and made sure they match.
Things I tried:
Call Shell("explorer.exe" & " " & Chr(34) & "S:\Shared" & Chr(34),
vbNormalFocus)
Shell "explorer.exe " & Chr(34) & FreightFile_Path & Chr(34), vbNormalFocus
Shell "explorer.exe" & " " & FreightFile_Path, vbNormalFocus
Dim retVal
retVal = Shell("explorer.exe" & " " & FreightFile_Path, vbNormalNoFocus)
Dim i As String
i = "explorer.exe" & " " & FreightFile_Path
Shell i, vbNormalFocus
FreightFile_Path = "S:\Supply Chain\Freight"
Shell "explorer.exe " & FreightFile_Path, vbNormalFocus
Restarted the application, restarted the computer.
Upvotes: 2
Views: 168
Reputation: 20871
I just had the same problem. In my case, it turned out to be anti-virus that was blocking Shell
. It just so happened that IT had put exceptions in place for my computer for one database but not the other. See my question and answer for more detail.
Upvotes: 1
Reputation: 23
Thank you everybody for the help. This might not really be an answer to the Shell
problem, but it will work for opening a file path.
Dim FreightFilePath As String
FreightFilePath = "S:\Supply Chain\Freight"
Application.FollowHyperLink FreightFilePath
Upvotes: 0
Reputation: 5731
New try. Use a WinAPI call
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 lpnShowCmd As Long) As Long
Public Sub ShellEx(ByVal Path As String, Optional ByVal Parameters As String, Optional ByVal HideWindow As Boolean)
If Dir(Path) > "" Then
ShellExecute 0, "open", Path, Parameters, "", IIf(HideWindow, 0, 1)
End If
End Sub
Sub Test()
FreightFile_Path = "S:\Supply Chain\Freight"
ShellEx "c:\windows\explorer.exe", """" & FreightFile_Path & """"
End Sub
Upvotes: 0
Reputation: 5731
Try this:
FreightFile_Path = "S:\Supply Chain\Freight"
Shell "cmd /c start explorer.exe """ & FreightFile_Path & """"
It is a bit of a workaround, but it works...
Upvotes: 0