Bonjour à tous
voila j'arrive à me connecter à ma bdd mais mes valeurs ne se rentrent pas, quelqu'un aurait t'il une explication. Il me sélectionne mydate et me dit type d'argument Byref incompatible.
voila mon code du form
voila mon module
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 Dim mydate Dim mytime Dim i As Integer, j As Integer Dim Mabase As Bdd Private Sub ConnectBdd_Click() Dim msg As String, msginf As String For i = 0 To 2 If Text1(i).Text = "" Then j = j + 1 msginf = "Il manque " & j & " paramètres de connexion!" End If Next If j > 0 Then GoTo lastline End If StatusBar1.SimpleText = "" With Mabase .NameUser = Text1(0).Text .Passwd = Text2.Text .Server = Text1(1).Text .NameDB = Text1(2).Text msg = .Connecter End With If msg = "OK" Then msginf = "Connexion à la Bdd réussie!" SaveInBdd.Enabled = True Else msginf = "Connexion à la Bdd échouée! Erreur: " & msg End If lastline: StatusBar1.SimpleText = msginf End Sub Private Sub Exit_Click() 'Si on clique sur le bouton"quitter" alors on reçoit le msg suivant Dim var As Integer 'Initialise "var" comme un entier var = MsgBox("Etes-vous sûr de vouloir quitter?", vbOKCancel, "Attention") 'Confirmation de sortie If (var = 2) Then Exit Sub End If Unload Form1 End Sub Private Sub SaveInBdd_Click() Dim pds As Double Dim cpnt As Byte Dim Codep As String Dim Rapports(2) As String Dim var As String Dim Use As String Dim Pass As String mytime = VBA.Time mydate = VBA.Date On Error GoTo lastline 'mydate = Date 'mydate = Format(Year(mydate) & "-" & Month(mydate) & "/" & Day(mydate), "yyyy-mm-dd") 'mytime = Time Codep = Code_Produit.Text Use = Text1(0).Text Pass = Text2.Text For i = 0 To 2 Rapports(i) = Replace(Text3(i).Text, ",", ".") Next var = Mabase.Ecrire(mydate, mytime, Codep, Pass, Use, Rapports()) If var = "OK" Then StatusBar1.SimpleText = "Ecriture dans la base de données réussie!" Else StatusBar1.SimpleText = var End If Exit Sub lastline: StatusBar1.SimpleText = "Erreur dans la mise en forme des données,vérifiez les informations rentrées!)" End Sub Private Sub Form_Load() Set Mabase = New Bdd Text1(0).Text = "root" Text1(1).Text = "127.0.0.1" Text1(2).Text = "Brownie" Text2.Text = "pauleta" 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
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 Option Explicit Dim cnx As ADODB.Connection Dim rst As ADODB.Recordset Dim cd As ADODB.Command 'variables locales de stockage des valeurs de propriétés Private mvarNameUser As String 'copie locale Private mvarPasswd As String 'copie locale Private mvarNameDB As String 'copie locale Private mvarServer As String 'copie locale Public Property Let Server(ByVal vData As String) mvarServer = vData End Property Public Property Get Server() As String Server = mvarServer End Property Public Property Let NameDB(ByVal vData As String) mvarNameDB = vData End Property Public Property Get NameDB() As String NameDB = mvarNameDB End Property Public Property Let Passwd(ByVal vData As String) mvarPasswd = vData End Property Public Property Get Passwd() As String Passwd = mvarPasswd End Property Public Property Let NameUser(ByVal vData As String) mvarNameUser = vData End Property Public Property Get NameUser() As String NameUser = mvarNameUser End Property Public Function Ecrire(d As String, Heure As String, CdProd As String, Pass As String, Use As String, Rapps() As String) As String On Error GoTo line1 Set cd.ActiveConnection = cnx Dim msg As String msg = "OK" d = Now cd.CommandText = "INSERT INTO ronaldinho (User, Password, CodeProduit, Date, Heure, Rapport1, Rapport2, Rapport3) VALUES ('" & Use & "', '" & Pass & "' ,'" & CdProd & "','" & d & "','" & Heure & "','" & Rapps(0) & "','" & Rapps(1) & "','" & Rapps(2) & "');" cd.execute GoTo lastline line1: msg = cnx.Errors.Item(0) lastline: cnx.Errors.Clear Ecrire = msg End Function Public Function Connecter() As String On Error GoTo line1 Dim msg As String msg = "OK" cnx.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};database=" & NameDB & ";server=" & Server & ";uid=" & NameUser & ";pwd=" & Passwd & ";" cnx.Open GoTo lastline line1: 'msg = cnx.Errors.Item(0) lastline: Connecter = msg cnx.Errors.Clear 'If cnx.State = adStateOpen Then ' cnx.Close 'End If 'Définition de la chaîne de connexion 'Ouverture de la base de données End Function Private Sub Class_Initialize() 'Initialisation de la connexion Set cnx = New ADODB.Connection Set cd = New ADODB.Command End Sub Private Sub Class_Terminate() 'If cnx.State = adStateOpen Then ' cnx.Close 'End If End Sub
Partager