Add.item in combo box not working

J

Jacy Erdelt

I created the following code, so when the form pops up the combo box should
populate with those values, but it doesn't. When the form pops up there is
nothing listed in the box. The only way I have been able to get it to
populate is if a specify a cell range in the boxes properties, but not all of
the properties I want are listed consecutively (and I would like to keep it
that way, if possible). What am I doing wrong?

Private Sub frmEnterNewConsult_Initialize()
'Fill ComboBox
With cboStore
.AddItem "178"
.AddItem "203"
End With

cboStore.Value = ""

Store.SetFocus

End Sub

Your help is greatly appreciated!
 
M

Mike H

Hi,

If you right click your userform and view code you can get all the events
for that form and you will note that the initialize event doesn't include the
userform name. If you put your code in that then it will work. I tested it
like this

Sub test()
frmEnterNewConsult.Show
End Sub

Private Sub UserForm_Initialize()
With cboStore
.AddItem "178"
.AddItem "203"
End With
End Sub

Mike
 
J

Jacy Erdelt

Thank you for your response. I am still a little confused. And I hope that I
can explain what I see or rather am not seeing without spreading my
confusion.

I may have misinterpreted your statements, so bare with me while I clarify.
You wrote that the initialize event does not include the userform name, so
then the code written should actually say "UserForm_Initialize()"? And the
..Show should be written under the UserForm object? Because before I had the
..Show attached to the Button on the main sheet and the form would come up
when I tried to debug it or of course when I clicked the button, it just
didn't populate. Now that I've changed it to the way I thought you meant it,
the form doesn't come up all and I get the "Object Required" error.

I feel like this should be so easy, I don't know why I don't understand.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top