How do I open a folder from an access form?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to have a button on my form page to open one of my folders that
hold my excel spreadsheets. Is this possible?
 
I haven't found a way to open a folder, but you can open Excel with a buttton
and from excel you can open the files you want.

You can put a button on the form when the button wizard opens it hasa an
option to runapp. select this and you can select to run excel.
 
"Open folder from access form?" <Open folder from access
[email protected]> wrote in message
I would like to have a button on my form page to open one of my folders that
hold my excel spreadsheets. Is this possible?


Open a folder? In Windows Explorer?

Paste the following code into a new module, you will be able to call a
public sub to do this, e.g.

ExploreFolder "C:\MyStuff\"


' ********************** Code Starts **********************
Option Compare Database
Option Explicit

Private Declare Function apiGetWindowsDirectory& Lib "kernel32" _
Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, _
ByVal nSize As Long)

Private Function ReturnWinDir() As String

On Error GoTo Err_Handler

Dim strWinDir As String
Dim lngReturn As Long

Const MAX_PATH As Integer = 255

strWinDir = String$(MAX_PATH, 0)

lngReturn = apiGetWindowsDirectory(strWinDir, MAX_PATH)

If lngReturn <> 0 Then
strWinDir = Left$(strWinDir, lngReturn)
Else
strWinDir = ""
End If

Exit_Handler:

ReturnWinDir = strWinDir

Exit Function

Err_Handler:
strWinDir = ""
Resume Exit_Handler

End Function

Public Sub ExploreFolder(strFolder As String)

On Error GoTo Err_Handler

Dim strWinDir As String
Dim strAppName As String

strWinDir = ReturnWinDir()

If Len(strWinDir) > 0 Then

strAppName = strWinDir & "\EXPLORER.EXE /n,/e," & strFolder

Call Shell(strAppName, 1)

End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
' ********************** Code Ends **********************
 
Back
Top