Consulting

Results 1 to 16 of 16

Thread: Controls on the fly

  1. #1
    VBAX Regular
    Joined
    Mar 2007
    Posts
    47
    Location

    Controls on the fly

    hey! i'm stuck again! i've designed userform (frmMy) with multipage (multiP). page1 contains frame (frameD). i want to populate this frame with labels, based on my worksheet. code:

    Dim Labes As MSForms.Label

    for x=15 to 1 step - 1
    set Labes = frmMy.multiP.Pages(0).frameD.designer.controls.add("forms.label.1")
    with Labes
    .top = 20
    end with
    next x

    all i get is error on set command - Object doesn't support this property or method. any help?? thanx

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Can I ask why your creating them on the fly...your asking for problems. Why not just put the label on the form where you want it and populate it based on your worksheet code?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Regular
    Joined
    Mar 2007
    Posts
    47
    Location
    hi lucas the problem is, that amount of labels will change (based on sheet data) through time. user can add some data to sheet, and i want to display them on label.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Mar 2007
    Posts
    47
    Location
    OK, thanx. i get it... but now, i have about 30 checkboxes and two problems arises:
    a) how to automatically populate captions (yes, i can use checkbox.caption = cells("1","A"); but how to make it easier)
    b) i want to check all of them, if they are clicked, and do some code...
    any help?

    sorry i'm newbie so please have patience with me

  6. #6
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    9 times out of 10, if you have that many controls on a user form you could probably use a rethink on your design - could you post a sample workbook?

  7. #7
    VBAX Regular
    Joined
    Mar 2007
    Posts
    47
    Location
    unfortunately i can't. it's made for internal company purposes. but believe me, i have to have these checkboxes on my form. they are for selecting different input variables for calculations.. any more help?

  8. #8
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Is there a naming convention that you've used for your checkboxes?

  9. #9
    VBAX Regular
    Joined
    Mar 2007
    Posts
    47
    Location
    CheckBox1, CheckBox2...

  10. #10
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Private Sub UserForm_Initialize()
    For i = 1 To 3
    Me.Controls("Checkbox" & i).Caption = Cells(i, 1)
    Next
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    You could use something like the following, however there are a few assumptions:
    1. The numbering of the checkboxes is consecutive, with no gaps in the numbering;
    2. The number of the checkbox corresponds with the row on the sheet in some way (the code below assumes the data is in column A, with the caption for Checkbox1 in row 1, the caption for Checkbox2 in row 2 etc.)
    [vba]
    Dim i As Integer


    For i = 1 To 30
    UserForm1.Controls("Checkbox" & i).Caption = SheetName.Cells(i, 1)
    Next i
    [/vba]

  12. #12
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Curses, pipped at the post!

  13. #13
    VBAX Regular
    Joined
    Mar 2007
    Posts
    47
    Location
    wow! perfect! THANX!
    Last edited by CicoMico; 06-27-2007 at 12:41 AM.

  14. #14
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Quote Originally Posted by geekgirlau
    Curses, pipped at the post!
    Well if you had a social life...... this wouldn't have happened!!!
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by geekgirlau
    Curses, pipped at the post!
    I only did it for 3, so much quicker!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Why not use a listbox?

    You can set it's properties to display checkboxes next to each item and to allow multiple selection.

Posting Permissions

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