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
| Option Explicit
Dim cn As ADODB.Connection
Private WithEvents rsCorrespondants As ADODB.Recordset
Dim bndCorrespondant As BindingCollection
Private Sub Form_Load()
Dim SQL As String
Dim strConnex As String
Dim i As Integer
Set cn = New ADODB.Connection
Set rsCorrespondants = New ADODB.Recordset
Set bndCorrespondant = New BindingCollection
'Chaîne de connexion
strConnex = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Developpez.com\Essais réponses\Agenda\Agenda.mdb;Persist Security Info=False"
'Requête SQL
SQL = "SELECT * FROM Correspondants"
'Connexion
cn.Open strConnex
'Création du recordset
rsCorrespondants.CursorLocation = adUseClient
rsCorrespondants.Open SQL, cn, adOpenDynamic, adLockOptimistic, adCmdText
Set DataGrid1.DataSource = rsCorrespondants
'Définit le jeu d'enregistrements comme source de données (DataSource) de la collection Bindings.
Set bndCorrespondant.DataSource = rsCorrespondants
With bndCorrespondant
.Add txtCorresp(0), "Text", "Nom", , "Nom"
.Add txtCorresp(1), "Text", "Prenon", , "Prenom"
.Add txtCorresp(2), "Text", "Adresse", , "Adresse"
End With
End Sub
Private Sub cmdNav_Click(Index As Integer)
Select Case Index
Case 0
rsCorrespondants.MovePrevious
Case 1
rsCorrespondants.MoveNext
End Select
End Sub |
Partager