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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Combo boxes population

Status
Not open for further replies.

nieironsio

Vendor
Oct 13, 2006
39
GB
Hello - I am having problem populating my combo boxes and list boxes. I have coded the following:

Private Sub UserForm_Initialize()
textb1.Value = ""

With combobox1
.AddItem "A"
.AddItem "B"
End With
cb1.Value = ""

textbox1.SetFocus
End Sub

This works fine but for some reason when you click another button on my userform next time i go back to combo box 1 A and B are there twice so my list becomes abab instead of ab.

Any help would be much appreciated - thanks - Nie
 
when adding items, you should always clear first unless you are adding iteratively:

Code:
Private Sub UserForm_Initialize()
textb1.Value = ""

With combobox1
.clear
.AddItem "A"
.AddItem "B"
End With
cb1.Value = ""

textbox1.SetFocus
End Sub

However, the root cause of this is that your userform is being initialised multiple times - something in your code on other controls must be doing this...probably shouldn't be...


Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top