Bonjour,
Je dois modifier un code qui devrait mettre à jour une base access à partir d'un fichier excel (en csv pour l'instant et xls par la suite).
Mais le problème c'est que je n'arrive pas à faire cette mise à jour.
Je m'explique, j'ai fais des tests sur le bout de code ci-dessous et lorsque j'arrive à l'enreg.update, il me sort une erreur mais j'ai beau chercher, je ne vois pas pourquoi j'aurais une erreur à cet endroit.
Je me demande s'il ne s'agit pas d'un problème venant de la requête mais je n'arrive pas à voir si ça pourrait être le cas.
Merci d'avance pour votre aide
PS : Je suis nouveau sur le forum donc si j'ai fais des erreurs, je m'en excuse
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 Public Sub Charge() Dim Enreg As Recordset Dim NomFich As String Dim NumFich As Integer Dim NumTyp As Integer Dim NumMot As Integer Dim NumBit As Integer Dim TabMots(22) As String Dim Ligne As String Dim nbMots As Integer Dim i As Integer If Maj = "OUI" Then On Error GoTo ErrCharge NumFich = FreeFile 'Ad_bd = dirdoc + "mon_fichier.csv" NomFich = Ad_bd If Trim(NomFich) <> "" And Dir$(NomFich) <> "" Then Open NomFich For Input As NumFich Do While Not EOF(NumFich) Input #NumFich, Ligne nbMots = ExtracMotLigneFich(Ligne, TabMots()) If (nbMots < 0) Then Exit Do End If If (Left(TabMots(0), 1) <> "T") And (TabMots(0) <> "") And (TabMots(1) <> "") And (TabMots(2) <> "") Then NumTyp = TabMots(0) NumMot = TabMots(1) NumBit = TabMots(2) 'permet la connexion à la bdd Set base = OpenDatabase(BdBase, False) Set Enreg = base.OpenRecordset("SELECT * FROM type_enreg WHERE Type=" & NumTyp & " AND Num_mot=" & NumMot & " AND Num_Bit=" & NumBit, dbOpenDynaset) If Not Enreg.EOF Then Enreg.Edit Enreg("Libelle0") = TabMots(7) Enreg("Libelle1") = TabMots(8) Enreg("Libelle2") = TabMots(9) Enreg("Libelle3") = TabMots(10) Enreg("Libelle4") = TabMots(11) Enreg("Libelle5") = TabMots(12) Enreg("Libelle6") = TabMots(13) Enreg("Libelle7") = TabMots(14) Enreg("Libelle8") = TabMots(15) Enreg("Libelle9") = TabMots(16) Enreg("Libelle10") = TabMots(17) Enreg("Libelle11") = TabMots(18) Enreg("Libelle12") = TabMots(19) Enreg("Libelle13") = TabMots(20) Enreg("Libelle14") = TabMots(21) Enreg.Update End If Enreg.Close End If Loop Close NumFich End If End If Exit Sub ErrCharge: MsgBox "bad" On Error GoTo 0 End Sub
Partager