Bind text box to a data-aware object?
Posted on 2001-06-17
Following VB help, I made a data-aware class (DataSourceBehavior = 1-vbDataSource) with a
recordset variable reCustomers.
I then read data from a txt file into the fields of the recordset.
I then created an object objCustomers to the class and can access the fields by
objCustomers.rsCustomers as if playing with database, fine. (see the attached class)
My problem is: how to link a text box with a field in the recordset? I tried
Set Text1.DataSource = objCustomers
Text1.DataField = "CompanyName"
without and error and without success:-(
Public rsCustomers As ADODB.Recordset
Private Sub Class_Initialize()
Dim fld As ADODB.Field
Dim strRow As String
Dim items As Variant, i As Long
Set rsCustomers = New ADODB.Recordset
' Set CustomerID as the primary key.
.Fields.Append "CustomerID", adChar, 5, adFldRowID
.Fields.Append "CompanyName", adChar, 40, adFldUpdatable
.Fields.Append "Fax", adChar, 24, adFldMayBeNull
' Use Keyset cursor type to allow updating records.
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
Open "c:\Customers.txt" For Input As #1