Solved

Bind text box to a data-aware object?

Posted on 2001-06-17
4
212 Views
Last Modified: 2012-06-27
Hi experts,

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:-(

----------the class------------

Option Explicit
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

   With rsCustomers
            ' 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
   End With

   Open "c:\Customers.txt" For Input As #1
   'input data.....
   Close #1

End Sub
0
Comment
Question by:learn
  • 3
4 Comments
 
LVL 6

Expert Comment

by:JonFish85
ID: 6200268
try using the Class_GetDataMember() procedure:

Private Sub Class_GetDataMember(DataMember As String, Data As Object)
  Set Data = rsRecordSetName
End Sub
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6200271
rsRecordSetName = rsCustomers in your case I believe
0
 

Author Comment

by:learn
ID: 6200329
Hi jonFish85,

What is Class_GetDataMember() for and what is rsRecordSetName in your commant?
Than you for your help....but, I still don't know how to link a text box with the recordset from the class:-(
0
 
LVL 6

Accepted Solution

by:
JonFish85 earned 60 total points
ID: 6200391
according to microsoft, GetDataMember() returns "the recordset to the client application to provide data binding". rsRecordsetName is the name of the recordset that you open in the class, which in your case is rsCustomers. Your full code should look like this:

'--------- Code starts ------------
Option Explicit
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

  With rsCustomers
           ' 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
  End With

  Open "c:\Customers.txt" For Input As #1
  'input data.....
  Close #1

End Sub

Private Sub Class_GetDataMember(DataMember As String, Data As Object)
 Set Data = rsCustomers
End Sub
'---------------- End code --------------


try that
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question