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
|
Option Explicit
Private colBndNwind As New BindingCollection
Private rsNwind As New ADODB.Recordset
Private cn As New ADODB.Connection
Private Sub Form_Load()
' Définit les paramètres de l'objet Connection.
With cn
' La connexion suivante peut ne pas fonctionner
' sur votre ordinateur.
' Modifiez-la pour trouver le fichier Nwind.mdb
' fourni avec Visual Basic.
.Provider = "Microsoft.Jet.OLEDB.3.51"
.Open App.Path & "\Nwind.mdb"
End With
' Ouvre le jeu d'enregistrements.
rsNwind.Open "Select * From Produits", cn
' Définit le jeu d'enregistrements comme source de
' données (DataSource) de la collection Bindings.
Set colBndNwind.DataSource = rsNwind
' Ajoute à la collection Bindings.
With colBndNwind
.Add Text1, "Text", "Nom du produit", , "produits"
.Add Text2, "Text", "Réf produit", , "produits"
End With
' Imprime les propriétés des objets de la collection.
Dim bndObj As Binding
For Each bndObj In colBndNwind
Debug.Print "DataField", "PropertyName", "Key"
Debug.Print bndObj.DataField, bndObj.PropertyName, bndObj.Key
Debug.Print
Next
End Sub
Private Sub Form_Click()
' Passe à l'enregistrement suivant en cliquant sur la feuille.
rsNwind.MoveNext
End Sub |
Partager