Thanks Thanks:  0
Likes Likes:  0
Results 1 to 6 of 6

Thread: create a control array

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Arkansas
    Posts
    358
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Im kind of new at this vb, trying hard to learn it. I have a form with frames. Nead to create a control array and have no idea of what I am doing.. Please help. Thx Dan

  2. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Not sure exactly what you mean by control array or what you want. But try the following code:

    Dim toppostition, counter As Integer
    counter = 5

    For I = 1 To counter
    Set myoptionbuttons(I) = MyFrame.Controls.Add("Forms.optionbutton.1")
    myoptionbuttons(I).Left = 0
    myoptionbuttons(I).Top = topposition
    myoptionbuttons(I).Width = 66
    myoptionbuttons(I).Height = 18
    myoptionbuttons(I).value= false
    myoptionbuttons(I).caption = Range("A" & counter).Value
    topposition = topposition + 18
    Next I

    This code will place 5 optionbuttons underneath each other starting at the top left corner of a frame called "MyFrame" and set the caption to the values in cells A1 through A5.


    _________________
    Hope this helps.
    Kind regards, Al.

    [ This Message was edited by: Al Chara on 2002-03-22 19:38 ]

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Arkansas
    Posts
    358
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    My problem is under this frame all option boxes have the same name with different captions. And I keep getting the error message - ambigouos name.

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You cannot create a control array in VBA unless something has changed...

  5. #5
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Each object must have it's own unique name

    A control array with optionbuttons for ex. would look like the following

    optionbutton(0).caption
    optionbutton(1).caption
    optionbutton(2).caption
    optionbutton(3).caption

    Unless VBA 6.0 has changed from 5.0, you cannot create a control array

  6. #6
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    See my code above, I updated it to fit your needs.
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

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
  •