Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bind text box to a data-aware object?

Posted on 2001-06-17
4
Medium Priority
?
230 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 240 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
Suggested Courses

704 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