
adding a Binding Yes/No field to a control fail please help
Please can somebody help me
i try to bind a yes/no field to a control on a form (checkbox) but te value
don't react
the problem is i can't find te right information of the propery field
i want to add controls to a form with all possibilities of a database (text
/ boolean / time / date / etc...., number , integer)
but i can't find the right information about using the property field of
Bindings collection.
thanx for help
Option Explicit
Private colBndNwind As New BindingCollection
Private rsNwind As New ADODB.Recordset
Private cn As New ADODB.Connection
'references
' Microsoft data binder collection
' Microsoft axtivex data objects 2.5 library
Private Sub Form_Load()
' Set the Connection object parameters.
With cn
' The following connection may or may not work on your computer.
' Alter it to find the Nwind.mdb file, which is included with
' Visual Basic.
.Provider = "Microsoft.Jet.OLEDB.3.51"
.Open "C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB"
End With
' Open the recordset object.
rsNwind.Open "Select * From Products", cn
' Add Textbox
Form1.Controls.Add "VB.TextBox", "txtproduct"
Form1.Controls("txtproduct").Top = 100
Form1.Controls("txtproduct").Width = 2000
Form1.Controls("txtproduct").Height = 120
Form1.Controls("txtproduct").Left = 700
Form1.Controls("txtproduct").Visible = True
'Add check box
Form1.Controls.Add "VB.CheckBox", "chkbxDiscontinued"
Form1.Controls("chkbxDiscontinued").Top = 500
Form1.Controls("chkbxDiscontinued").Width = 2000
Form1.Controls("chkbxDiscontinued").Height = 120
Form1.Controls("chkbxDiscontinued").Left = 700
Form1.Controls("chkbxDiscontinued").Visible = True
Form1.Controls("chkbxDiscontinued").Visible = True
' Set the DataSource of the Bindings collection to the recordset.
Set colBndNwind.DataSource = rsNwind
'Add to the Bindings collection.
With colBndNwind
.Add Me.Controls("txtproduct"), "Text", "ProductName", , "product"
.Add Me.Controls("chkbxDiscontinued"), "Value", "Discontinued", ,
"Discontinued"
End With
' Print the properties of the objects in the collection.
Dim bndObj As Binding
Debug.Print "DataField", "PropertyName", "Key"
For Each bndObj In colBndNwind
Debug.Print bndObj.DataField, bndObj.PropertyName, bndObj.Key
Next
Debug.Print
End Sub
Private Sub Form_Click()
' Move to the next record by clicking the form.
rsNwind.MoveNext
End Sub