[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

create a combobox at runtime and fill with data on a multipage userform Page tab

Posted on 2013-05-14
6
Medium Priority
?
1,253 Views
Last Modified: 2013-05-14
vba excel 2010

What I have:
Userform =  userform1
Multipage control =  Pages 1 to 9

I found this code:

But this code does not place the combobox on a userform and specifically "Page9"  ?





Sub CreateComboBox1()
    With ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", _
                Link:=False, DisplayAsIcon:=False, Left:=50, Top:=80, Width:=100, _
                Height:=15)
        With .Object
            .AddItem "Date"
            .AddItem "Player"
            .AddItem "Team"
            .AddItem "Goals"
            .AddItem "Number"
        End With
    End With
End Sub


Thanks
fordraiders
0
Comment
Question by:Fordraiders
  • 3
  • 3
6 Comments
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 39165258
This code will add a combobox to Page9 of a multipage at runtime.
Private Sub UserForm_Initialize()
Dim cbo As MSForms.ComboBox

    Set cbo = Me.MultiPage1.Pages(8).Controls.Add("Forms.Combobox.1")
    cbo.Left = 10
    cbo.Top = 10
    cbo.List = Array("Date", "Player", "Team", "Goals", "Number")
    
End Sub

Open in new window

0
 
LVL 3

Author Comment

by:Fordraiders
ID: 39165310
Thanks, The reason i was trying to find code using the
            .AddItem "Date"
            .AddItem "Player"
            .AddItem "Team"
            .AddItem "Goals"
            .AddItem "Number"

Is because I may have sometimes 50 items or more to add to the combobox ?

or maybe if i have to use another line, (using your code) how to multiline it.(to extend the array list to another line would be fine) ?


Also
imnorie, just a question...I noticed browsing through code that most show code using  Initialize event.  This can be done regardlesss from a command button or some event from another combobox ?

Thanks very much fordraiders
0
 
LVL 35

Expert Comment

by:Norie
ID: 39165337
You can change the code I posted to use AddItem.
With cbo
       .AddItem "Date"
       .AddItem "Player"
       .AddItem "Team"
       .AddItem "Goals"
       .AddItem "Number"
End With

Open in new window

By the way, where will the 50 (or whatever) items be coming from?

You could call the code from a command button click or some other event, I posted for the Initialize event because your title mentioned adding at runtime.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:Fordraiders
ID: 39165449
By the way, where will the 50 (or whatever) items be coming from?
hard coding it...
0
 
LVL 35

Expert Comment

by:Norie
ID: 39165505
Oh, thought they might have been stored somewhere, eg a worksheet.

That would have made it a lot easier to populate the combobox and would avoid hard-coding.
0
 
LVL 3

Author Closing Comment

by:Fordraiders
ID: 39165911
thanks very much
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question