BrokenBiker
ManicMechanic
- Local time
- Today, 10:17
- Joined
- Mar 22, 2006
- Messages
- 128
I'm using a browsing function to allow the user to select where previously selected files will be moved to. There are many examples/means to open a dialog box to select files, but I've only been able to find one that selects the folder location.
Ghudson's example works great, but I can't seem to find where to modify the code for it to default to a certain folder--"C:\MyFolder\" for instance.
Here's the module:
...And here's the Sub from the form's button:
Ghudson's example works great, but I can't seem to find where to modify the code for it to default to a certain folder--"C:\MyFolder\" for instance.
Here's the module:
Code:
Option Compare Database
Option Explicit
'http://www.mvps.org/access/api/api0002.htm
'Code courtesy of Terry Kreft
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseDirectory(szDialogTitle As String) As String
On Error GoTo Err_BrowseDirectory
Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer
With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With
dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
If X Then
wPos = InStr(szPath, Chr(0))
BrowseDirectory = Left$(szPath, wPos - 1)
Else
BrowseDirectory = ""
End If
Exit_BrowseDirectory:
Exit Function
Err_BrowseDirectory:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_BrowseDirectory
End Function
Public Function TestOpeningDirectory()
On Error GoTo Err_TestOpeningDirectory
Dim sDirectoryName As String
sDirectoryName = BrowseDirectory("Find and select where to export the Excel report files.")
If sDirectoryName <> "" Then MsgBox "You selected the '" & sDirectoryName & "' directory.", vbInformation
Exit_TestOpeningDirectory:
Exit Function
Err_TestOpeningDirectory:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_TestOpeningDirectory
End Function
...And here's the Sub from the form's button:
Code:
Private Sub btn_BrowseMoveOld_Click()
Dim sDirectoryName As String
Me.tbHidden.SetFocus
sDirectoryName = BrowseDirectory("Find and select where to export the report files.")
tbDirectoryName = sDirectoryName
End Sub