Solved

Bind text box to a data-aware object?

Posted on 2001-06-17
4
202 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now