Solved

Bind text box to a data-aware object?

Posted on 2001-06-17
4
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

739 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