Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

Bind controls to a class's property in VB6

Hello I have a class that is bound to a recordset.  I also have a form with several controls on it.  These controls are currently bound to the recordset.  But what I want them to be bound to is the class's property, so that it calls the property Get and Let procedure when it needs or saves data.

The reason for this is that the database has some user-unfriendly values such as Y or N for True and False so I want to put a checkbox on the form and have the value property of the checkbox bound to the class's property get and let procedure so that I can return True or False and not Y or N.

I will be greatly appreciative of any responses.
0
Jagar
Asked:
Jagar
  • 4
  • 3
  • 2
1 Solution
 
tcurtinCommented:
use the property get to return 0 or -1 as boolean for false or true respectively.
0
 
JagarAuthor Commented:
It never calls the property get it goes directly to the database.  That's why I need to know how to set up the class as a data source correctly because obviously I'm doing something wrong.
0
 
tcurtinCommented:
Use a property in the class to connect to the recordset. Open a connection in the class's initialize event:
  in the client:
dim x as Class1
Private sub command1_click()
   set x = new class1
   x.customername = txtCustomername.text
   'repeat property setting for all fields
end sub
 Property Let CustomerName(strCustomer as string)
       con.execute("insert into " _                            &        "customers('Customer_name') " _
       & "values (" & strcustomer & ")"
end property

I hope this is closer. I'm using ADO. A super book is by Sams. Visual Basic 6. Database How to. It focuses on ADO and Crystal reports..... Written by The Waite's Group.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
JagarAuthor Commented:
There is some way to automatically bind the controls to the class.  So that you do not have to explicitely set the class's propertys to the text values of the controls.
0
 
tcurtinCommented:
Use VB6's data environment to establish a connection to the data source. The Data Member can be a command(stored Procedure,SQL string). Then map the 'DataMember' property to the data environment(command), then the data field property to the database field.
0
 
JagarAuthor Commented:
Please provide an example of what you are doing I half understand it, because I have half of it setup, but I don't know what I'm missing.
0
 
MirkwoodCommented:
In VB6 this is easy. The following text is directly from the VB help. You can find it yourself. In VB 5 it is not possible.

Creating the MyDataSource Class


In the previous topic, we created a class that implements an OLE DB Simple Provider. In this step we'll create another class that will provide data from the MyOSPObject class to other objects.

Note   This topic is part of a series that walks you through creating sample data source components. It begins with the topic Creating Data Sources.

To create the MyDataSource class

Select the MyDataComponent project in the Project Explorer.


Select Add Class Module from the Project menu, then choose Class Module from the Add Class Module dialog box.


Select the Properties window and set the following properties for the new class module:Property Setting
(Name) MyDataSource
DataSourceBehavior 2-vbOLEDBProvider


In the Object box, select Class. In the Procedure box, select the GetDataMember event. Add the following code to the Class_GetDataMember event procedure:
Private Sub Class_GetDataMember(DataMember As String, Data As Object)
   ' Declare an instance of the MyOSPObject class
   Dim MyOSP As New MyOSPObject

   ' Make sure the DataMember is valid
   If DataMember = "" Then
       Err.Raise (E_FAIL)
   End If

   ' Set the FilePath property
   MyOSP.FilePath = DataMember

   ' Call the LoadData method to populate the class
   MyOSP.LoadData

   ' Set MyDataSource's data to MyOSPObject's data
   Set Data = MyOSP
End Sub

Choose Save Project Group from the File menu to save your changes. When prompted for a file name for the Class module, choose the default (MyDataSource.cls).
As you may have noticed, this class is much simpler than the MyOSPObject class. In fact, if you go back and compare it with the GetDataMember event, you'll see that it's doing essentially the same thing. The main difference here is that we're using a class that we created rather than the pre-existing ADODB class.

In the next step, we'll convert the form that we created earlier to use our new data source object, and we'll test it to see the results.

Step by Step
This topic is part of a series that walks you through creating sample ActiveX data sources.

To See
Go to the next step Testing the MyData Component
Start from the beginning Creating Data Sources

0
 
JagarAuthor Commented:
That looks like what I could be looking for, but could you tell me where in the Help files you found this, so that I can review the whole thing (about the previous chapter and all)  I some how missed this when I was looking through the help files.
0
 
MirkwoodCommented:
Just press F1 in VB6. Search for "Creating the MyDataSource Class"
and you will find this topic.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now