Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding items to comboboxes added at runtime

Status
Not open for further replies.

sjulian

Programmer
Aug 15, 2000
56
0
0
US
I want to add comboboxes to a form based on the number of records in a db table. Each combo box is to be populated with the same choices. I found code for adding the comboboxes, but have been unable to determine how to add items to them.
I am adding the comboboxes with the code below:
Code:
Private Sub AddControlSet()
        Dim c As Control
        
        c = New ComboBox()
        c.Name = "cboInputFile"
        c.Top = Me.Controls.Count + 1 * 25
        c.Left = 5
        c.Width = 125
        Me.Controls.Add(c)
        c.Text = "SELECT file"
        c = New ComboBox()
        c.Name = "cboIMSColumns"
        c.Top = Me.Controls.Count + 1 * 25
        c.Left = 5 + Me.Controls.Item(Me.Controls.Count - 1).Width + 5
        c.Width = 125
        Me.Controls.Add(c)
        Me.Controls.Item(Me.Controls.Count - 1).Text = "Select File"
        c = New Button
        c.Name = "Rule"
        c.Top = Me.Controls.Count + 1 * 25
        c.Left = Me.Controls.Item(Me.Controls.Count - 1).Left + Me.Controls.Item(Me.Controls.Count - 1).Width + 5
        c.Height = Me.Controls.Item(Me.Controls.Count - 1).Height
        Me.Controls.Add(c)
        Me.Controls.Item(Me.Controls.Count - 1).Text = "Rule"
End Sub
I tried using
Code:
c.items.add
but that isn't available.
Can someone post or point me to instructions that I need?
Thanks
 
I also want to be able to set some properties of the comboboxex and don't see how to do that either.
 

You need to either keep a reference to the index of each combobox, so you can access it through the form's Controls collection, or use the code in this FAQ:

faq796-5698

to access the combobox by name. Once you do that, you should be able to add items, etc.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top