Link to home
Start Free TrialLog in
Avatar of Jagar
Jagar

asked on

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.
Avatar of tcurtin
tcurtin

use the property get to return 0 or -1 as boolean for false or true respectively.
Avatar of Jagar

ASKER

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.
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.
Avatar of Jagar

ASKER

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.
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.
Avatar of Jagar

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jagar

ASKER

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.
Just press F1 in VB6. Search for "Creating the MyDataSource Class"
and you will find this topic.