slt a tous
quel qu’un peut me dire pourquoi ce code n'enregistre rien ? il marche parfaitement sans les conditions if ismissing.
je doit faire une enregistrement de 2 tables avec une seul fonction mais 2 forme différente
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
'Class Module
Option Explicit
 
Private db As Database
 
Private v_champ1 As Variant
Private v_champ2 As Variant
Private v_champ3 As Variant
Private v_champ4 As Variant
Private v_champ5 As Variant
Private v_champ6 As Variant
Private v_table As Variant
 
Public Property Get champ1() As Variant
champ1 = v_champ1
End Property
Public Property Let champ1(a As Variant)
v_champ1 = a
End Property
 
Public Property Get champ2() As Variant
champ2 = v_champ2
End Property
Public Property Let champ2(b As Variant)
v_champ2 = b
End Property
 
Public Property Get champ3() As Variant
champ3 = v_champ3
End Property
Public Property Let champ3(c As Variant)
v_champ3 = c
End Property
 
Public Property Get champ4() As Variant
champ4 = v_champ1
End Property
Public Property Let champ4(d As Variant)
v_champ4 = d
End Property
 
Public Property Get champ5() As Variant
champ5 = v_champ5
End Property
Public Property Let champ5(e As Variant)
v_champ5 = e
End Property
 
Public Property Get champ6() As Variant
champ6 = v_champ6
End Property
Public Property Let champ6(F As Variant)
v_champ6 = F
End Property
 
Public Property Get table() As Variant
table = v_table
End Property
Public Property Let table(g As Variant)
v_table = g
End Property
 
Public Sub insertion(champ1 As Variant, Optional champ2 As Variant, Optional champ3 As Variant, Optional champ4 As Variant, Optional champ5 As Variant, Optional champ6 As Variant)
Dim m As String
m = MsgBox("voulez-vous enregistrer?", vbYesNo + vbQuestion, "Enregistrer")
    If m = vbYes Then
        If IsMissing(champ5) And IsMissing(champ6) Then
            db.Execute "INSERT INTO " & v_table & " VALUES ('" & champ1 & "','" & champ2 & "','" & champ3 & "','" & champ4 & "')"
        Else
        If IsMissing(champ3) And IsMissing(champ4) And IsMissing(champ5) And IsMissing(champ6) Then
            db.Execute "INSERT INTO " & v_table & " VALUES ('" & champ1 & "','" & champ2 & "')"
        End If
    End If
End If
End Sub
 
 
Private Sub Class_Initialize()
Set db = OpenDatabase("E:\Logiciel\DTS\VB6\Access\Bon de commande.mdb")
End Sub
 
Private Sub Class_Terminate()
db.Close
End Sub
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
'Form
Option Explicit
 
Private Sub cmdEnregistrer_Click()
'On Error Resume Next
Dim x As ProjectDLL.insertion
Set x = New ProjectDLL.insertion
x.Table = "Fournisseur"
 
x.champ1 = "Code FRNS"
x.champ2 = "Nom FRNS"
x.champ3 = "Adresse FRNS"
x.champ4 = "Telephone"
 
x.champ1 = Text1.Text
x.champ2 = Text2.Text
x.champ3 = Text3.Text
x.champ4 = Text4.Text
 
x.insertion(text1.text & text2.text & text3.text & text4.text)
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub