Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Repost: Add Control to UserForm

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Once you add a control to a userform during runtime, how to activate/access the events such as _click()?

    These controls work at runtime, such as a checkbox toggling on and off but I can not program an event.

    Thanks for any help


  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You can add code at run time as well. You need to set a reference to Visual Basic Extensibility, but, I saw, I think Damon Ostrander, make a suggestion, like this:

    If you know you MAY add a checkbox at run time, and you need the_Click() sub, you can create the Sub at Design time with the name of the control you will have at run time, that way, if the control is added, it'll have its _Click() event.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  3. #3
    New Member
    Join Date
    Mar 2002
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Juan: Thanks for looking into this.

    ** I am not having any trouble adding a control, such as a checkbox, at run time. I am able to add the control with the following statements. **

    Dim TestCheckbox As Control

    Sub Private Whatever()

    Set TestCheckbox = _ Controls.Add("Forms.Checkbox.1", _ "TestCheckbox", True)

    End Sub

    ** Now if I add the following sub routine, it is treated as a standalone subroutine, not an event associated with the checkbox: **

    Sub Private TestCheckbox_Click()
    End Sub

    ** To further complicate matters, I tried the following test. **

    Dim WithEvents SingleButton As CommandButton

    Sub Private Whatever()

    Set SingleButton = _ Controls.Add("Forms.CommandButton.1", _ "SingleButton", True)

    End Sub

    Sub Private SingleButton_Click()
    SingleButton.Cpation = "Changed"
    End Sub

    ** This works. The VBA compiler will allow
    "Dim WithEvents SingleButton As CommandButton" but not Dim WithEvents SingleButton As CheckBox" **

    Any clues?

    [ This Message was edited by: LaShark on 2002-03-27 08:10 ]

    [ This Message was edited by: LaShark on 2002-03-27 08:21 ]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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