Results 1 to 3 of 3
2010-02-26, 15:40 #1
- Join Date
- Jun 2004
- Lambertville, New Jersey, USA
- Thanked 0 Times in 0 Posts
I have a report generation form that allows the user to i/p selection criteria and run various reports. Some of the reports are saved to a default folder.
I want to provide the user with the ability to "browse" and select the folder to save the files to. I've been all through my many reference books but can't find a starting point. Any guidence would be appreciated.
I'm using Access 2002/2003 for this one.
2010-02-26, 16:42 #2
- Join Date
- Apr 2001
- Cambridge, UK
- Thanked 3 Times in 3 Posts
If you are using Access 2003, you could try using the Microsoft Common Dialogue Control.
You can place it on a form and call it with a button.
CommonDialogue1.ShowOpen for example
It does not actually open a file, but returns the selected file name with the
If you then use InstrRev with Left, you would be able to find the Last \
and thus get the Folder Name selected.
As far as I can remember the Common Dialogue will not work in Access 2000.
I am willing to be corrected on that.Andrew
2010-02-26, 20:16 #3
- Join Date
- Aug 2002
- Brisbane, Queensland, Australia
- Thanked 1 Time in 1 Post
Stick the following in a module -
Option Compare Database Option Explicit 'This module contains all the declarations to use the Windows 95 Shell API to use the browse for folders 'dialog box. To use the browse for folders dialog box, please call the BrowseForFolders function using the 'syntax: stringFolderPath=BrowseForFolders(Hwnd,TitleOfDialog) Public Type BROWSEINFO hwndOwner As Long pidlRoot As Long pszDisplayName As Long lpszTitle As Long ulFlags As Long lpfnCallback As Long lParam As Long iImage As Long End Type Public Const BIF_RETURNONLYFSDIRS = 1 Public Const MAX_PATH = 260 Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long) Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long Public Declare Function SHBrowseForFolder Lib "shell32" (lpBI As BROWSEINFO) As Long Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long Public Function BrowseForFolder(Optional hwndOwner As Long = 0, Optional sPrompt As String = "Find Directory") As String Dim iNull As Integer Dim lpIDList As Long Dim lResult As Long Dim sPath As String Dim udtBI As BROWSEINFO 'initialise variables With udtBI .hwndOwner = hwndOwner .lpszTitle = lstrcat(sPrompt, "") .ulFlags = BIF_RETURNONLYFSDIRS End With 'Call the browse for folder API lpIDList = SHBrowseForFolder(udtBI) 'get the resulting string path If lpIDList Then sPath = String$(MAX_PATH, 0) lResult = SHGetPathFromIDList(lpIDList, sPath) Call CoTaskMemFree(lpIDList) iNull = InStr(sPath, vbNullChar) If iNull Then sPath = Left$(sPath, iNull - 1) End If 'If cancel was pressed, sPath = "" BrowseForFolder = sPath End Function
strFolder = BrowseForFolder()
this will open the folder browser and return the path to the folder the user selects.