Compléments pour Microsoft Access

http://access.fr.free.fr/

Sélectionner répertoire (Fichier)

Description 

Ce code permet d'ouvrir une boîte de dialogue afin de sélectionner un répertoire.

Vous devez copier tout le code qui suit dans un module que vous pouvez appeler "modApiOpenDir".

 
Synthaxe 

Expression = GetDirectory (msg)

La synthaxe de la fonction GetDirectory comprend l'élément suivant :

ElémentsDescription

msg

Facultatif. Expression  de chaîne correspondant au message que l'on souhaite afficher dans la boîte de dialogue qui va s'ouvrir.
 
Exemple 

Aucun exemple disponible pour le moment.

 
Code de la fonction 


'***************************Debut du code***************************

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

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

Public 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

bInfo.pidlRoot = 0

If IsMissing(Msg) Then
     bInfo.lpszTitle = "Select a folder."
Else
     bInfo.lpszTitle = Msg
End If

bInfo.ulFlags = &H1

X = SHBrowseForFolder(bInfo)

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

'***************************Fin du code***************************