1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
Sub SltDsrMg()
Dim fd As Office.FileDialog
Dim ChmSlct As String: Dim Nbfch1 As Integer
Dim oRst As DAO.Recordset
Dim oDb As DAO.Database
Dim tbl1 As DAO.TableDef
Dim NbFchMprt As Integer: Dim NbFchXst As Integer
Dim Msg As String
Dim RChm As String
Dim x As Integer: Dim y As Integer
Set oDb = CurrentDb
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
' Ce formulaire affiche tous les chemins enregistrés
DoCmd.OpenForm "F_DsrMg", acNormal, "", "", acFormEdit, acWindowNormal
fd.Title = "Sélectionnez un dossier..."
If fd.Show() Then
ChmSlct = fd.SelectedItems(1) & "\"
' x représente le nombre de chemins déjà dans la base
x = DCount("ChmRgn", "R_DsrMg")
For y = 0 To x
If IsNull(Forms!F_DsrMg!ChmRgn) Then
MsgBox "Votre base de données ne contient aucun fichier", vbDefaultButton1
y = x
Else
'Début du problème: je ne sais pas boucler sur chaque occurence afin de contrôler la 'présence du chemin
If Forms!F_DsrMg!ChmRgn <> ChmSlct Then
MsgBox " Le dossier sélectionné n' est pas dans la base", vbDefaultButton1
' Dans un premier temps s' arrêter ici car pour la suite, je préfére tester le résultat avant 'de vous importuner sur une solution que je peux peut-être trouver!!!
Else
If Forms!F_DsrMg!ChmRgn = ChmSlct Then
MsgBox "Ce dossier est déjà enregistré", vbDefaultButton1
Exit Sub
End If
End If
End If
Next y
' compte le nombre de fichier dans le dossier sélectionné
Nbfch1 = NbFch(ChmSlct) - 1
'contrôle que la table TP_Chm n'existe pas
For Each tbl1 In CurrentDb.TableDefs
If tbl1.Name = "TP_Chm" Then
DoCmd.RunSQL "DROP Table " & "TP_Chm" 'efface la table si elle existe
Exit For
End If
Next
'Création de la table TP_Chm
If IsNull(Forms!F_DsrMg!ChmRgn) Then
NbFchXst = 0
Else
RChm = "SELECT T_Pht.Cf_Pht, T_Pht.ChmRgn, T_Pht.NmFch INTO TP_Chm"
RChm = RChm & "FROM T_Pht;"
DoCmd.RunSQL RChm
'Compte le nombre de fichier existant dans la base
NbFchXst = DCount("Cf_Pht", "TP_Chm")
End If
DoCmd.Close acForm, "F_DsrMg", acSaveNo
'Compare le nombre de fichiers à importer et le nombre de fichier existant dans votre base
If NbFchXst = Nbfch1 Then
MsgBox "Ce dossier existe dans la base de donnée. Il est complet", vbDefaultButton1
Exit Sub
Else
If NbFchXst < Nbfch1 Then
Msg = " La base de donnée contient " & NbFchXst & " cliché(s) sur " & Nbfch1 & ""
Msg = Msg + " à importer. Faut-il continuer l' importation de ce dossier "
If MsgBox(Msg, vbExclamation + vbYesNo) = vbYes Then
ChgMg ChmSlct, "*.jpg"
ChgMg ChmSlct, "*.bmp"
Else
Exit Sub
End If
End If
End If
End If
Set fd = Nothing
End Sub |
Partager