Bonjour,

J'ai un module me permettant d'importer des données à partir de fichier excel. Dans ce module, j'importe les informations dans une table temporaire (CONTACTS_IMPORT) et je souhaite pouvoir ajouter ou modifier les enregistrements qui existent déja dans ma table (nommé CONTACTS).

Voila le code :
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
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
 
    On Error GoTo Err_cmd_Importer_Click
 
        'Controle l'accès
    If F_Administrateur = False Then
       MsgBox "Vous n'avez pas le droit d'y accéder  (^_^)   !!", vbOKOnly, "Droit d'accès"
       Exit Sub
    End If
 
    Dim dbs As DAO.Database, Rst As DAO.Recordset, Rst_Import As DAO.Recordset
    Dim Exist_Enr As Boolean
 
    Set dbs = CurrentDb
    Set Rst_Import = dbs.OpenRecordset("CONTACTS_IMPORT")
 
        'Importation de fichier *.XLS
        'Utilisation de la fenêtre FichierSélect pour l'importation à partir d'excel
 
    Dim repert, feuille, base As String, fic As Variant
    Dim cible, CibleData As String
    Dim strSQL As String
 
    base = "cibleImport"
                'récupération du fichier à importer
    Crit = "[base] ='" & base & "'"
    m_bouton = "Valider la Sélection"
    m_sélFicAnnulé = True
    DoCmd.OpenForm "FichierSélect", acNormal, , Crit, acFormEdit, acDialog
    If m_sélFicAnnulé Then Exit Sub
                'récupération du répertoire sélectionné
    repert = DLookup("[répertoire]", "Variables", Crit)
    fic = DLookup("[fich_Data]", "Variables", Crit)
                'nettoyage et récupération des données
    videTable "CONTACTS_IMPORT"
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "CONTACTS_IMPORT", repert & fic, True
 
    delTableImportErrors
 
        'controle de décalage pb de point virgule
    ChampListeCréa
 
 
    Set Rst = dbs.OpenRecordset("CONTACTS")
 
    With Rst_Import
        .MoveFirst
        Do While Not .EOF
            Rst.FindFirst ("Cont_CodeInterne = '" & !Cont_CodeInterne & "'")
            If Rst.NoMatch Then     'Ne trouve pas l'enregistrement
                Rst.AddNew
            Else
                Rst.Edit
            End If
 
            'Rst.AddNew
            Rst!Cont_CodeInterne = !Cont_CodeInterne
            Rst!Cont_societe = !Cont_societe
            Rst!Cont_Societe2 = !Cont_Societe2
            Rst!Cont_Civilite = !Cont_Civilite
            Rst!Cont_Nom = !Cont_Nom
            Rst!Cont_Prenom = !Cont_Prenom
            Rst!Cont_Fonction = !Cont_Fonction
            Rst!Cont_Adr1 = !Cont_Adr1
            Rst!Cont_Adr2 = !Cont_Adr2
            Rst!Cont_Adr3 = !Cont_Adr3
            Rst!Cont_Cp = !Cont_Cp
            Rst!Cont_Ville = !Cont_Ville
            Rst!Cont_PrefixePays = !Cont_PrefixePays
            Rst!Cont_TelStandard = !Cont_TelStandard
            Rst!Cont_TelDirect = !Cont_TelDirect
            Rst!Cont_TelPortable = !Cont_TelPortable
            Rst!Cont_Fax = !Cont_Fax
            Rst!Cont_Mail = !Cont_Mail
            Rst!Cont_TailleSociete = !Cont_TailleSociete
            Rst!Cont_Inst = !Cont_Inst
            Rst!Cont_Expl = !Cont_Expl
            Rst!Cont_Ind = !Cont_Ind
            Rst!Cont_UtilisateurFinal = !Cont_UtilisateurFinal
            Rst!Cont_Distr = !Cont_Distr
            Rst!Cont_Deshumidifacation = !Cont_Deshumidifacation
            Rst!Cont_Humidification = !Cont_Humidification
            Rst!Cont_Deshydratation = !Cont_Deshydratation
            Rst!Cont_Climatisation = !Cont_Climatisation
            Rst!Cont_Chauffage = !Cont_Chauffage
            Rst!Cont_EnergRenouvenable = !Cont_EnergRenouvenable
            Rst!Cont_Commercial = !Cont_Commercial
            Rst!Cont_Commentaire = !Cont_Commentaire
            Rst!Cont_Commentaire1 = !Cont_Commentaire1
            Rst!cont_Commentaire2 = !cont_Commentaire2
            Rst!Cont_Selection = !Cont_Selection
            Rst!Cont_TypeClient = !Cont_TypeClient
            Rst!Cont_Part = !Cont_Part
            Rst!Cont_Divers = !Cont_Divers
            Rst!Cont_BE = !Cont_BE
            Rst!Cont_DateDerniereVisite = !Cont_DateDerniereVisite
 
            Rst.Update
            .MoveNext
        Loop
    End With
 
    Me.Refresh
    MsgBox "Importation des données terminées.", vbApplicationModal + vbOKOnly, "Importation de données"
 
        'Décharge la mémoire
    Rst.Close
    Rst_Import.Close
    Set Rst = Nothing
    Set Rst_Import = Nothing
    Set dbs = Nothing
 
Exit_Err_cmd_Importer_Click:
    DoCmd.SetWarnings True
    Exit Sub
 
Err_cmd_Importer_Click:
    MsgBox Error$
    Resume Exit_Err_cmd_Importer_Click
Lorsque je lance l'importation, une erreur survient sur la permière ligne de cette partie :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
            Rst.FindFirst ("Cont_CodeInterne = '" & !Cont_CodeInterne & "'")
            If Rst.NoMatch Then     'Ne trouve pas l'enregistrement
                Rst.AddNew
            Else
                Rst.Edit
            End If
Donc j'aimerai savoir s'il est possible de programmer comme ça et sinon quelle serait mon erreur.

Je précise aussi que l'erreur est : 3251 Opération non autorisé pour ce type d'objet.

Si l'un(e) d'entre vous a une idée sur ce problème ça me dépannerait bien.

Merci d'avance