Access ouvrir un explorer Windows et récupérer le chemin

Résolu
Bonjour à toutes et à tous,
Etant bloqué car je ne trouve pas de solution j'ai besoin de votre clairvoyance.
Voilà, Sur Access dans une entête j'ai ajouté un bouton qui quand j'appuie dessus, le programme doit ouvrir un explorateur de fichier et quand je choisi un fichier le programme doit me retourner dans une zone de texte le chemin du fichier choisie.
Le bouton s'appelle RACINE_AFFAIRE, et la zone de texte s'appelle CHEMIN et pour finir, voici le début de programme du bouton :

Option Compare Database
Private Sub RACINE_AFFAIRE_Click()
Shell "explorer /e,,", vbMaximizedFocus
End Sub

Je vous remercie d'avance.

1 réponse

  1. Bonjour ,

    Pourquoi ouvrir l'exploreur de windows par une commande Shell ???

    Application.FileDialog(msoFileDialogFilePicker)
    Ca pause moins de probleme

    https://docs.microsoft.com/fr-fr/office/vba/api/access.application.filedialog?redirectedfrom=MSDN

    seule chose a faire, remplacer

    'Loop through each file selected and add it to our list box. 
             For Each varFile In .SelectedItems 
                Me.FileList.AddItem varFile 
             Next  


    par

    Chemin=.SelectedItems(1)
    1
    1. Merci pour la rapidité de ta réponse.
      J'ai fait exactement ce que tu ma dit de faire mais pour la phrase:
      Dim fDialog As Office.FileDialog Access marque "Erreur de compilation Type défini par l'utilisateur non défini" du coup j'ai essayé avec juste FileDialog mais c'est le même résultat.
      0
    2. @Nintendoboy59Bonjour,

      Avez-vous coche cette reference
      Outils, reference cocher microsoft office xx.x object library
      0
    3. En effet, la case n'était pas cocher, ce problème est résolue mais, maintenant Access me dit "Erreur de compilation Membre de méthode ou de données introuvable" pour la méthode ".FileList" de la phrase "Me.FileList.RowSource = "" ".
      0
    4. @Nintendoboy59Re,

      Le code de micorsoft est un exemple, il faut l'adapter a votre besoin, ex:
      Option Compare Database

      'Outils, reference cocher microsoft office xx.x object library
      Private Sub RACINE_AFFAIRE_Click()

      ' Requires reference to Microsoft Office 11.0 Object Library.

      Dim fDialog As Office.FileDialog
      Dim varFile As Variant

      ' Clear listbox contents.
      'Me.FileList.RowSource = ""

      ' Set up the File Dialog.
      Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

      With fDialog

      ' Allow user to make multiple selections in dialog box
      .AllowMultiSelect = True

      ' Set the title of the dialog box.
      .Title = "Please select one or more files"

      ' Clear out the current filters, and add our own.
      .Filters.Clear
      .Filters.Add "Access Databases", "*.MDB"
      .Filters.Add "Access Projects", "*.ADP"
      .Filters.Add "All Files", "*.*"

      ' Show the dialog box. If the .Show method returns True, the
      ' user picked at least one file. If the .Show method returns
      ' False, the user clicked Cancel.
      If .Show = True Then
      xx = .SelectedItems(1) 'Chemin complet
      'Loop through each file selected and add it to our list box.
      For Each varFile In .SelectedItems
      'Me.FileList.AddItem varFile
      x = varFile 'nom de fichier
      Next

      Else
      MsgBox "You clicked Cancel in the file dialog box."
      End If
      End With
      End Sub
      0
    5. j'ai finis par trouver la réponse,
      en mettant ce code:
      e Database
      Private Sub RACINE_AFFAIRE_Click()
      ' ---
      ' SELECTION SIMPLE DE FICHIER
      ' ---
      '
      Dim fd As Office.FileDialog

      ' Créer un objet FileDialog
      Set fd = Application.FileDialog(msoFileDialogOpen)

      ' Titre de la boîte de dialogue
      fd.Title = "Sélectionnez un fichier..."

      ' Ne pas autoriser la sélection multiple
      ' (donc 1 seul fichier est sélectionnable à la fois)
      fd.AllowMultiSelect = False

      ' Afficher la boîte de dialogue
      If fd.Show() Then
      CHEMIN = fd.SelectedItems(1)
      End If

      Merci pour ton aide ^^
      0