PDA

Click to See Complete Forum and Search --> : Creating an ActiveX control that connects to a database


666539
Sep 21st, 2000, 04:28 PM
I'm trying to create a simple activeX control that validates user input. The ActiveX control only has a textbox and the activeX control filters out the type of characters that are entered into the textbox.

I want to know how to set up the activeX properties so that I can pass datasource and datafield to the textbox. I'm new to this so maybe this isn't what I need to do. Any advice is appriciated.

Sep 21st, 2000, 04:34 PM
one way to do it is to add a data environment to your project. you then right click on the connection to see its properties, and connect to your oledb source. then you click on the data view toolbar button, pick the table you want, and drag it to the data environment window.

then you set the textbox properties..datasource, datafield, and/or datamember.

hope this helps.

sanon
Sep 21st, 2000, 09:41 PM
Another way to achive that is:


Public Property Get DataSource() As Variant
DataSource = Text1.DataSource
End Property

Public Property Let DataSource(ByVal vNewValue As Variant)
Text1.DataSource = vNewValue
PropertyChanged "DataSource"
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
DataSource = PropBag.ReadProperty("DataSource", "")
DataField = PropBag.ReadProperty("DataField", "")
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "DataSource", Text1.DataSource, ""
PropBag.WriteProperty "DataField", Text1.DataField, ""
End Sub

Public Property Get DataField() As Variant
DataField = Text1.DataField
End Property

Public Property Let DataField(ByVal vNewValue As Variant)
Text1.DataField = vNewValue
PropertyChanged "DataField"
End Property

666539
Sep 22nd, 2000, 02:42 PM
Sanon,

Have you gotten the code you posted to work or was that just off the top of your head? I've tried working with that code and I can't get it to work.

666539
Sep 23rd, 2000, 12:10 AM
I've figured out how to do what I was asking about in my original post. It was pretty easy.

I created an activex control with 1 text box.

I crated a propety "text" for that activex control and coded the let and get methods.

Then you have to go into the procedure attributes and choose the "Property is data bound" and "This property binds to datafield"

That's all you have to do and when you use this activex control on a form you will have more properties available to set up the datasource and datafields properties.

AllanJensen
Oct 11th, 2000, 04:45 AM
The method 666539 showed us works, you where right, it is easy
But I don't seem to be able to change the value of the database when I write a new string in the textbox. I can only browse through the database. That cannot be right, right?

666539
Oct 11th, 2000, 09:04 AM
Hi Allan

Thanks for pointing that out. I looked into that and found the problem. The link below will give a detailed explaination of how to create these controls. In short, you have to call the PropertyChanged method on the bound property if you want the control to be updatable.

If you have a text box in your activeX control, in the text1_changed event you have to have the code
PropertyChanged "text"
(assuming that the property of your activeX control that holds the text from text1 is named "text")


http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbcon98/vbconbindingyourolecontroltodatasource.htm