CommonDialog

Résolu
amel3011 Messages postés 18 Date d'inscription mercredi 5 novembre 2008 Statut Membre Dernière intervention 14 avril 2009 - 9 nov. 2008 à 16:11
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 - 9 nov. 2008 à 16:32
Bonjour,
je cherche une propriété de CommonDialog qui m'aiderais à spécifier un chemin.
j'utilise le code suivant pour ouvrir une base de donnée et par la même occasion trouver son chemin, mais maintenant je veut spécifié juste le chemin ou un repertoire sans choisir un fichier

     With dlgCommonDialog
        'À faire définir les indicateurs et attributs
        'du contrôle des dialogues communs
        .Filter = "Fichiers Bases de données Accesss (*.mdb)|*.mdb"
        .DialogTitle = "Veuillez choisir la base de données RD"
        .ShowOpen
        If Len(.FileName) = 0 Then
        Chercher_Chemin = False
        Else
        chemin_rd = .FileName
        End If
    End With
Merci

4 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
9 nov. 2008 à 16:19
salut,

pas possible de sélectionner juste un répertoire avec le common dialog

voici le code (une manière) à mettre en place, dans un module



<hr />
'    BOITE DE DIALOGUE POUR CHOISIR UN RÉPERTOIRE
'    http://www.codyx.org/snippet_boite-dialogue-pour-choisir-repertoire_512.aspx#1881
'    Posté par [ 401740 PCPT ] le 11/06/2008
<hr />




Private 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
Private Const BIF_RETURNONLYFSDIRS As Long
= 1&
Private Const MAX_LENGTH  As Long = 512&
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

Function BrowseDirectory(Optional ByVal lHandle As Long = 0, Optional
ByVal sTitle As String
= vbNullString) As
String
'   crée à partir de
l'API-GUID
    Dim tBI As BrowseInfo, lRet As Long, sBuffer As String
    With tBI
        .hWndOwner = lHandle
        .lpszTitle = lstrcat(sTitle, vbNullChar)
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    lRet = SHBrowseForFolder(tBI)
    If lRet Then
        sBuffer = String$(MAX_LENGTH, vbNullChar)
        Call SHGetPathFromIDList(lRet, sBuffer)
        Call CoTaskMemFree(lRet)
        sBuffer = LeftB$(sBuffer, InStrB(sBuffer, vbNullChar))
        BrowseDirectory = sBuffer
    End If
End Function





'----------------------------------------------------------------



'Remarques :


'MsgBox BrowseDirectory(Me.hWnd, "Sélectionnez un dossier...")






++

<hr size ="2" width="100%" />
Prenez un instant pour répondre à [forum/sujet-SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp 
3
amel3011 Messages postés 18 Date d'inscription mercredi 5 novembre 2008 Statut Membre Dernière intervention 14 avril 2009
9 nov. 2008 à 16:26
ok merci je v essayer de l'adapter à mon code
merci bcp
0
amel3011 Messages postés 18 Date d'inscription mercredi 5 novembre 2008 Statut Membre Dernière intervention 14 avril 2009
9 nov. 2008 à 16:31
ça marche tres bien merci bcp
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
9 nov. 2008 à 16:32
pense au bouton Réponse acceptée si la réponse te convient
++
0
Rejoignez-nous