Solved

Bind text box to a data-aware object?

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

785 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