We help IT Professionals succeed at work.

MS Access Question: how to launch file explorer

HIROYUKI TAMURA
HIROYUKI TAMURA used Ask the Experts™
on
Hi Experts,
I would like to launch file explorer from MS access by clicking a button with certain path.
Would you advise me?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
President / Owner CARDA Consultants Inc.
Distinguished Expert 2018
Commented:
One of the easiest way is
Application.FollowHyperlink "YourPath"

Open in new window

Application.FollowHyperlink "C:\Temp\"

Open in new window


Another approach could be to use Shell
Shell "C:\WINDOWS\explorer.exe ""YourPath", vbNormalFocus

Open in new window

Shell "C:\WINDOWS\explorer.exe ""C:\Temp\", vbNormalFocus

Open in new window

Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Depends on what you want to do.  If you want to select a file to be used by your application, or select a folder to be used to store a file you are exporting from your applicaiton, you will need to use the FileDialog object.  There are numerous examples here in EE about how to use the FileDialog feature.  I suggest you search on that term.
Daniel PineaultPresident / Owner CARDA Consultants Inc.
Distinguished Expert 2018

Commented:
Very valid point Dale!  

If this is to allow the user to select a file and return the filename to the application, then you should be looking at using the FileDialog, see: https://www.devhut.net/2016/10/04/late-binding-the-filedialog/
ste5anSenior Developer

Commented:
By using the Shell method:

Shell "explorer.exe ""C:\Temp\"""

Open in new window


E.g. as method do handle the path escaping:

Option Compare Database
Option Explicit

Public Sub ExplorerOpenDirectory(ByVal CPath As String)

  Const DELIMITER As String = """"
  Const EXPLORER As String = "explorer.exe ""?"""

  Shell Replace(EXPLORER, "?", Replace(CPath, DELIMITER, DELIMITER & DELIMITER)), vbNormalFocus

End Sub

Open in new window

John TsioumprisSoftware & Systems Engineer

Commented:
And here a Windows API variation : http://access.mvps.org/access/api/api0001.htm