Locate a speciic folder in Access

rickyfong

Registered User.
Local time
Today, 05:58
Joined
Nov 25, 2010
Messages
199
In order to act as a system, I would like to have a function or windows firstly displayed all the folder names in a drive, and then allow user to locate/select freely a folder among different folders. Is there anything for my reference or for me to start?? Thanks a lot!!
 
Here is a function that opens a browsing dialogue box and should give you what you need

Code:
Function dialogFolderBrowse() As String
    '##### This function gives the user the facility to browse for a file or folder and to be able to use the path
    '##### as a destination.
    '##### You must include the Microsoft Office Object Library, go to Tools/References
    '##### Returns the selected folder address
    '##### written by ??    
Dim fp As FileDialog
Dim vrtSelectedItem As Variant
Dim varX As String
 
'this next line is an optional warning to the user so they know what is about to happen 
MsgBox "You will now be asked to browse to the required folder location", vbOKOnly
 
'Create a FileDialog object as a Folder Picker dialog box.
Set fp = Application.FileDialog(msoFileDialogFolderPicker) ' can use msoFileDialogFilePicker for filenames
fp.AllowMultiSelect = True
If fp.Show = -1 Then
        'this is the only way I've been able to assign the selected path as a value to string variable
     For Each vrtSelectedItem In fp.SelectedItems
          varX = vrtSelectedItem
 
                'vrtSelectedItem is a String that contains the path of each selected item.
 
     Next vrtSelectedItem
 
End If
 
dialogFolderBrowse = varX
 
End Function

David
 
I got the following code, but ACCESS complained ...... it should be the shell32.dll. Any idea??

Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Declare Function SHBrowseForFolder Lib "
shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

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

Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer
' Root folder = Desktop
bInfo.pidlRoot = 0&
' Title in the dialog
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = Msg
End If
' Type of directory to return
bInfo.ulFlags = &H1
' Display the dialog
x = SHBrowseForFolder(bInfo)
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function

Private Sub Command1_Click()
Label1.Caption = GetDirectory
End Sub
 
In the module, it seems I have to inclue the MS office object library. Anyone can help?? I am using ACCESS 2003 but Chinese version, please printscreen and let me have a reference to see where is the Tools/References in order to select the Microsoft office object library. Thanks a lot!!

##You must include the Microsoft Office Object Library, go to Tools/References
 

Users who are viewing this thread

Back
Top Bottom