ShellExecute to view contents of a folder

J

John

I am trying to code a command button on an access form to open a window to
look at the contents of a particular folder held in the shared workfiles
space on our Server. (SBS2003)

Ideally I want code that simply enables me to open the folder and look at
its contents, rather than open a particular document.

I have tried using ShellExecute as follows:

Public 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

Code for OnClickEvent of cmdButton:

=connect(me.txtPath) where txtPath is the path to the folder

Public Sub Connect(strPath As String)
On Error GoTo Connect_Error

Dim StartDoc As Long
Dim SW_SHOWNORMAL As Long
If Not IsNull(strPath) Then
StartDoc = ShellExecute(Me.hwnd, "", Me.txtPath, _
"", "", SW_SHOWNORMAL)
End If
Exit Sub

Connect_Error:
MsgBox "Error: " & Err & " " & Error
Exit Sub
End Sub

I have successfully opened a document with this method if it is included in
the path.

ie when the path = "\\Server\Workfiles\Admin\SampleRep.doc", the document
opens.

However when the path only = "\\Server\Workfiles\Admin", startdoc returns 33
which I believe indicates success, but nothing else happens. This is
regardles of whether I use the "explore" verb in the lpOperation parameter
position. However if I use the "find" verb, this opens two (?!) explorer
search windows starting on the correct folder.

It seems tantalisingly close to success. Any hints gratefully received!
 
J

John Nurick

Hi John,

This works for me:

Shell "explorer.exe ""\\Server\Workfiles\Admin""", vbNormalFocus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top