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
| Option Explicit
Dim rs As ADODB.Recordset, cn As ADODB.Connection
Private Sub Form_Close()
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
Set cn = New ADODB.Connection
cn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Temp\COMPTOIR2.mdb"
cn.Open
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "SELECT * FROM Clients", cn, adOpenStatic, adLockOptimistic, adCmdText
Set Me.Recordset = rs
For i = 1 To 9
' libellé = Nom du champ
Me.Controls("lbl" & i).Caption = rs.Fields(i - 1).Name
' Source Contrôle Zone de texte
Me.Controls("txt" & i).ControlSource = rs.Fields(i - 1).Name
Next
End Sub |
Partager