Bonjour à tous,


J'ai une macro permettant de convertir un nombre en date (dans 3 colonnes différentes, d'où la partie Fonction), d'ajouter une colonne et d'y renseigner le numéro de semaine de cette même date.
Le but étant de :
=> Cliquer sur le bouton de formulaire Access pour selection des fichiers devant subir ces conversions (les enregistrer sous Excel)
=> Importer les données dans ma table Access

L'erreur de compilation est ici :
Nom : Annotation 2022-05-05 154901.jpg
Affichages : 99
Taille : 43,5 Ko
Comment lié les tous mes éléments ?

Mon code de conversion :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Sub TestAppli()
 
 
I = 2
While Cells(I, 1) <> "": I = I + 1: Wend
 
For l = 2 To I - 1
Cells(l, 3) = convertdat(Cells(l, 3))
Cells(l, 6) = convertdat(Cells(l, 6))
Cells(l, 7) = convertdat(Cells(l, 7))
Next
Columns("D:D").Insert Shift:=xlToRight
Cells(1, 4) = "Semaine"
For l = 2 To I - 1
Cells(l, 4) = DatePart("ww", Cells(l, 3), vbMonday, vbFirstFourDays)
Cells(l, 4).NumberFormat = "general"
Next
 
 
 
End Sub
 
 
Function convertdat(dat)
convertdat = DateSerial(Left(dat, 4), Mid(dat, 5, 2), Right(dat, 2))
End Function

Mon code d'importation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Sub importJRN()
 
'Déclaration des variables
Dim chemins() As Variant
Dim chemin As Variant
Dim tableCible As String
Dim sqlCommand As String
 
'Gestion des erreurs
'On Error GoTo gestionErreurs
 
'Choix du fichier source
chemins() = selectionFichiers("Z:\xx2022")
'Arret des messages system
DoCmd.SetWarnings False
 
'Boucle d'importation
For Each chemin In chemins()
 
    'Vérification présence
    If DCount("*", "tblSuiviMAJ", "NomFichier = " & Chr(34) & Dir(chemin) & Chr(34)) < 1 Then
 
        'Nettoyage de la table temp avant import
        sqlCommand = "DELETE FROM tblTempJRN"
        DoCmd.RunSQL sqlCommand
 
Call TestAppli
 
        'Import du fichier
        DoCmd.TransferSpreadsheet acImport, , "tblTempJRN", chemin, 1
 
 
        'Transfert de la table temp vers table finale
        sqlCommand = "INSERT INTO tblJRN ( NomFichier, Fournisseur, [Type Prev], [Date MSG], [Référence], Libelle, [Date début], [Date fin], Qte, [Fixation = A], [Num Message], [Date déb sélection] ) " & _
                    "SELECT """ & Dir(chemin) & """, tblTempJRN.Fournisseur, tblTempJRN.[Type Prev], tblTempJRN.[Date MSG], tblTempJRN.[Référence], tblTempJRN.Libelle, tblTempJRN.[Date début], tblTempJRN.[Date fin], tblTempJRN.Qte, tblTempJRN.[Fixation = A], tblTempJRN.[Num Message], tblTempJRN.[Date déb sélection] " & _
                    "FROM tblTempJRN"
        DoCmd.RunSQL sqlCommand
 
 
        'Suivi des MAJ
        sqlCommand = "INSERT INTO tblSuiviMAJ (TableCible, NomFichier, DateAjout, NbLignes) " _
                   & "VALUES (""tblJRN"", """ & Dir(chemin) & """, NOW(), Dcount(""*"", ""tblTempJRN""))"
        DoCmd.RunSQL sqlCommand
 
 
 
    End If
 
Next
 
'Fin et nettoyage
DoCmd.SetWarnings True
MsgBox "Importation Terminée"
Exit Sub
 
'Gestion des erreurs
gestionErreurs:
    Debug.Print Err.Number
    Debug.Print Err.Description
    DoCmd.SetWarnings True
    MsgBox "Erreur lors de l'importation"
 
 
 
End Sub

Merci par avance,
LRN