Consulting

Results 1 to 3 of 3

Thread: Get container and/or parent of dynamically created control (checkbox)

  1. #1
    VBAX Newbie
    Joined
    Dec 2014
    Posts
    1
    Location

    Get container and/or parent of dynamically created control (checkbox)

    I have dynamically created checkboxes by the use of a class module.
    I also have a dynamically created "Select All" checkbox. The purpose of this "Select all" checkbox is to set all other checkboxes in the same frame to the same value as the "Select all" checkbox.

    Can I use the parent or container property for dynamically created checkboxes (or controls in general)? Would that require that I specify the parent or container property in the class module (of course, I guess)?

    How would I have to go about this?

    Thanks!

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Why don't you design all controls in design mode and only make them visible/invisible at run time ?

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    I agree with snb that dynamically created controls are problematic, but if you create a control you can use the .Parent property to get it's container, which might be a user form, a Frame or a Page from a multipage control.

    Another way would be to use a (multi-select) ListBox with .ListStyle set to fmListStyleOption. Each dynamic checkbox could be a list item in such a listbox.

    This routine will return the user form object in which a control resides (not just the Frame/Page container).
    Function ParentUF(ctrl As MSForms.Control) As Object
            Set ParentUF = ctrl
            On Error Resume Next
            Do
                Set ParentUF = ParentUF.Parent
            Loop Until Err
            On Error GoTo 0
    End Function

Tags for this Thread

Posting Permissions

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