Consulting

Results 1 to 6 of 6

Thread: Solved: Userform events for dynamic controls

  1. #1
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location

    Solved: Userform events for dynamic controls

    Hi All,

    Not exactly an excel question, really applies to any office userform. This is just our busiest forum

    I'm adding a bunch of controls at runtime to my userform, and I need access to their _click events. I know how to do this if I were to use a class module, and I will probably end up doing that, but I'm really hoping to keep all the code in the userform itself.

    I know I could just put in a bunch of _click events in hopes that the number I add never goes above the pre-coded events, but I'm hoping for something better.
    Since I can't use control arrays in VBA, does anyone know a tricky way of doing this? Though I don't know of it, I'm hoping there something like:[vba]controls("controlname").assignevent "click", "myclickevent"[/vba]
    And in reality, this is for outlook, which has no VBE access so I can't even go that route.

    If you know for sure that there is no such thing, please post that too. I think chances are I'm just gonna have to deal with a class module for the time being (until I go the com add-in route).
    Matt

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You can write direcly to the code module for the userform. This reference should help
    http://www.ozgrid.com/forum/showthread.php?t=69411

  3. #3
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Wish I could.. unfortunately outlook doesnt have programmatic VBE access (I should have been more explicit) so that is out.

    I should just mark this solved, I decided to just go with the class module route and make the end users just import two files instead of one. Thanks though
    Matt

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Matt,

    Could you create/update the userform in some other app, and export it to Outlook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    I thought about that but can't bring it back into outlook at runtime (though I could just open it up in an instance of excel and show it there). Seems like its reaching though. I think once I make it into an add-in (back to one file) it will make things easier, and just deal with the separate class for now (I realized after I posted this that I probably shouldn't have )
    Matt

  6. #6
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Bob (or Mike), if you want to take a look and see if I'm just missing something, feel free. Its a photo viewer for attached images in outlook, I'll attach it here
    Matt

Posting Permissions

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