Results 1 to 7 of 7

Thread: Creating an ActiveX control that connects to a database

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    51
    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.

  2. #2
    Guest

    Lightbulb

    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.

  3. #3
    Lively Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    88
    Another way to achive that is:

    Code:
    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

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    51
    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.



  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    51
    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.


  6. #6
    New Member
    Join Date
    Mar 2000
    Location
    Denmark
    Posts
    2
    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?

    Allan

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    51
    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/de...datasource.htm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width