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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| Private Sub cmdImporterrepertoire_Click()
Dim dbs As Database
Dim rs As Recordset
Dim MyName As String
Dim MyPath As String
Dim MyDestination As String
Dim extension As String
Dim compteur As Integer
compteur = 0
Dim txtReponseImportMsgBox As Integer
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("tblDocument", dbOpenDynaset)
MyPath = DLookup("[RepertoireSource]", "tblParametreImportation", "[ParImpId] = 1")
'MyName = Dir(MyPath & "*.*") ' pour trouver tous les fichiers
Select Case opgFormatDocument
Case 1
MyName = Dir(MyPath & "*.pdf")
Me!AcroPDF6.Visible = True
Me!imgPhoto.Visible = False
Me!OleWord.Visible = False
Me!OleExcel.Visible = False
Case 2
MyName = Dir(MyPath & "*.jpg")
Me!imgPhoto.Visible = True
Me!AcroPDF6.Visible = False
Me!OleWord.Visible = False
Me!OleExcel.Visible = False
Case 5
MyName = Dir(MyPath & "*.*")
Me!OleWord.Visible = False
Me!OleExcel.Visible = False
Me!AcroPDF6.Visible = False
Me!imgPhoto.Visible = False
Case Else
End Select
If Me.chkTransferFichier Then
MyDestination = DLookup("[RepertoireDestination]", "tblParametreImportation", "[ParImpId] = 1")
End If
Dim FSys As Object
Dim TRACE As Object
Dim OpenTRACE
Dim LeFichierTrace As String
Dim Chemin As String
Dim reponse As String
Dim derniercree As String
Dim ExisteDansBase As Long
Dim CptExisteDansBase As Integer
CptExisteDansBase = 0
Dim passe As Integer
passe = 0
Dim result As String
LeFichierTrace = "c:\temp\TRACE.txt" ' fichier texte qui contiendra la liste des noms des fichiers
'Pour creer le fichier texte si il existe pas
Set FSys = CreateObject("Scripting.FileSystemObject")
If FSys.FileExists(LeFichierTrace) = False Then
Set TRACE = FSys.CreateTextFile(LeFichierTrace)
End If
'Ouverture en ecriture du Fichier texte
Set TRACE = FSys.GetFile(LeFichierTrace)
Set OpenTRACE = TRACE.OpenAsTextStream(2, -2)
'8 = ForAppending = Ouvre un fichier et écrit à la fin du fichier.
'2 = ForWriting
'1 = ForReading
Do While MyName <> ""
If Me.chkTransferFichier Then
ExisteDansBase = Nz(DLookup("[Docnum]", "tblDocument", "[Fichier] = '" & MyDestination & MyName & "' "), 0)
Else
ExisteDansBase = Nz(DLookup("[Docnum]", "tblDocument", "[Fichier] = '" & MyPath & MyName & "' "), 0)
End If
Debug.Print "ExisteDansBase " & ExisteDansBase
If ExisteDansBase > 0 Then
Me.txtReponseImportMsgBox = 7
CptExisteDansBase = CptExisteDansBase + 1
Debug.Print "ignorés "; CptExisteDansBase
Else
Select Case opgFormatDocument
Case 1 'Pdf
Me!AcroPDF6.src = MyPath & MyName
DoCmd.OpenForm "frmImportMsgBox", , , , , acDialog, MyPath & MyName
Case 2 'Photo
Me.imgPhoto.Picture = MyPath & MyName
DisplayPhoto
DoCmd.OpenForm "frmImportMsgBox", , , , , acDialog, MyPath & MyName
Case 5 'Autres formats
extension = Right(MyName, 3)
Debug.Print "ext "; extension
Select Case extension
Case "pdf", "doc", "xls", "jpg"
Me.txtReponseImportMsgBox = 7
Debug.Print "reponse "; Me.txtReponseImportMsgBox
Case Else
ShellExecute Me.hwnd, vbNullString, MyPath & MyName, "", vbNullString, 1
DoCmd.OpenForm "frmImportMsgBox", , , , , acDialog, MyPath & MyName
End Select
Case Else
MsgBox "Format non prévu"
End Select
' result = Nz(ExisteDansBase = DLookup("[Fichier]", "tblDocument", "[Fichier] = '" & MyPath & MyName & "' "), "")
End If
'Analyse de la réponse du formulaire frmImportMsgBox
Select Case Me.txtReponseImportMsgBox
Case 6 'Oui
'10/07 DoCmd.OpenForm "frmValeurDefaut", acNormal, , "[ParImpId] = 1", acFormEdit, acDialog
rs.AddNew
If Me.chkTransferFichier Then
rs![Fichier] = MyDestination & MyName
Else
rs![Fichier] = MyPath & MyName
End If
rs![Titre] = DLookup("[TitreDef]", "tblParametreImportation", "[ParImpId] = 1")
rs![Auteur] = DLookup("[AuteurDef]", "tblParametreImportation", "[ParImpId] = 1")
rs![Sujet] = DLookup("[SujetDef]", "tblParametreImportation", "[ParImpId] = 1")
rs![Motscles] = DLookup("[MotsClesDef]", "tblParametreImportation", "[ParImpId] = 1")
rs![Creationdate] = DLookup("[CreationDateDef]", "tblParametreImportation", "[ParImpId] = 1")
rs![Categorie] = DLookup("[CategorieDef]", "tblParametreImportation", "[ParImpId] = 1")
rs![Gisement] = DLookup("[GisementDef]", "tblParametreImportation", "[ParImpId] = 1")
rs![Importdate] = Time()
rs.Update
rs.MoveLast
derniercree = rs![Docnum]
'Debug.Print "avant copie " & MyName
If Me.chkTransferFichier Then
' Copie du fichier de l Emplacement Initial vers l Emplacement Final
FileCopy MyPath & MyName, MyDestination & MyName
'Debug.Print "après copie " & MyName
End If
DoCmd.OpenForm "frmDocumentImport", acNormal, , "Docnum =" & derniercree, acFormEdit, acDialog
'Debug.Print "après ouverture formulaire " & MyName
'__ Effacement du fichier sur l'emplacement initial LE FICHIER DOIT ETRE FERME
If Me.chkTransferFichier Then
Kill MyPath & MyName
End If
OpenTRACE.Write MyPath & MyName & (Chr(13) + Chr(10))
'Debug.Print "après openTRACE " & MyName
'Fichier suivant
MyName = Dir
'Debug.Print "après MyName = Dir " & MyName
compteur = compteur + 1
Case 7 'Non
passe = passe + 1
Debug.Print "passe " & passe
OpenTRACE.Write MyPath & MyName & (Chr(13) + Chr(10))
MyName = Dir
Case 2 'Annuler
FermerApplication
Exit Do
End Select
FermerApplication
Loop
Select Case compteur
Case 0
'soust =
MsgBox "Aucun document n'a été traité " & CptExisteDansBase & " documents ignorés car le fichier est déjà présents dans la base " & passe - CptExisteDansBase & " passés par vous même", 64, "Fin de la procédure d'importation"
Case 1
MsgBox "1 document a été traité " & CptExisteDansBase & " documents ignorés car le fichier est déjà présents dans la base " & passe - CptExisteDansBase & " passés par vous même", 64, "Fin de la procédure d'importation"
Case Else
MsgBox compteur & " documents ont été traités " & CptExisteDansBase & " documents ignorés car le fichier est déjà présents dans la base " & passe - CptExisteDansBase & " passés par vous même", 64, "Fin de la procédure d'importation"
End Select
'"Impossible de masquer le contrôle actif" pour word, excel
'Me.OleWord.Action = acOLEClose
'Me!OleWord.Visible = False
'Me!OleExcel.Visible = False
'solution: fermer le formulaire
Me!AcroPDF6.Visible = False
Me!imgPhoto.Visible = False
DoCmd.Close
End Sub |
Partager