VBA Combo Box Not Populating

Hello Experts,

I am currently using this code on my UserForm in Outlook.  For some reason, the Combo Box is not populating with my items.  Any ideas?

Private Sub RARequest_Activate()

    cboReason1.Clear
    cboReason2.Clear
    cboReason3.Clear
    cboReason4.Clear
    cboReason5.Clear
    
    
    'lbEmails.Clear

    cboReason1.AddItem "Test 1"
    cboReason2.AddItem "Test 2"
    cboReason3.AddItem "Test 3"
    cboReason4.AddItem "Test 4"
    cboReason5.AddItem "Test 5"
    
'    lbEmails.AddItem "Sample Request"
'    lbEmails.AddItem "Quote Request"
'    lbEmails.AddItem "Return Authorization Request"
'    lbEmails.AddItem "Order Expedite Request"
    
End Sub

Open in new window


Thank you in advance for your help!

~ Geekamo
LVL 1
GeekamoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
They probably are populating, you just can't see it.

Do cboReason1.ListIndex = 0 for example in your code after you fill them.
0
GeekamoAuthor Commented:
@ MartinLiss,

Hmm, something is wrong - received error.  (I have no clue what I'm doing...)

Private Sub RARequest_Activate()

    cboReason1.Clear
    cboReason2.Clear
    cboReason3.Clear
    cboReason4.Clear
    cboReason5.Clear
    
    
    'lbEmails.Clear

    cboReason1.AddItem "Test 1"
    cboReason2.AddItem "Test 2"
    cboReason3.AddItem "Test 3"
    cboReason4.AddItem "Test 4"
    cboReason5.AddItem "Test 5"
    
    Do cboReason1.ListIndex = 0
    
    
'    lbEmails.AddItem "Sample Request"
'    lbEmails.AddItem "Quote Request"
'    lbEmails.AddItem "Return Authorization Request"
'    lbEmails.AddItem "Order Expedite Request"
    
End Sub

Open in new window


~ Geekamo
0
Martin LissOlder than dirtCommented:
Leave out the "Do" in line 18.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

GeekamoAuthor Commented:
@ MartinLiss,

That didn't work either.

~ Geekamo
0
Martin LissOlder than dirtCommented:
Can you attach your wb then please?
0
GeekamoAuthor Commented:
@ MartinLiss,

wb = workbook?  I'm not using Excel.  I am using Outlook.  Here is the current version of the code, I am trying many different solutions I am finding on Google - but so far, nothing is working.  I'm not sure what I'm missing with all this...

Private Sub userform_Initalize()

'    cboReason1.Clear
'    cboReason2.Clear
'    cboReason3.Clear
'    cboReason4.Clear
'    cboReason5.Clear

'    With cboReason1
'        .AddItem 1
'        .AddItem 2
'    End With
    
    'lbEmails.Clear
    
    With AnimalComboBox
 .AddItem "Dog"
 .AddItem "Cat"
 .AddItem "Horse"
 .ListIndex = 0

 End With

'    cboReason1.RowSource = "Test 1"
'    cboReason2.AddItem "Test 2"
'    cboReason3.AddItem "Test 3"
'    cboReason4.AddItem "Test 4"
'    cboReason5.AddItem "Test 5"
    
    
'    cboReason1.ListIndex = 0
'    cboReason1.ListIndex = "Test 1"
'    cboReason2.ListIndex = "Test 2"
'    cboReason3.ListIndex = "Test 3"
'    cboReason4.ListIndex = "Test 4"
'    cboReason5.ListIndex = "Test 5"
    
    
'    lbEmails.AddItem "Sample Request"
'    lbEmails.AddItem "Quote Request"
'    lbEmails.AddItem "Return Authorization Request"
'    lbEmails.AddItem "Order Expedite Request"
    
End Sub

Open in new window

0
Martin LissOlder than dirtCommented:
Okay, several questions.
1.    Are the comboxes on the UserForm?
2.    Have you compiled your code?
3.    Do you have 6 comboboxes namedAnimalComboBox,  cboReason1, 2, 3, 4 and 5?
4.    Your code in lines 32 to 36 isn't valid. What were you trying to do? The ListIndex is the index into the combobox that represent the selected item. In other words if the user selected the second item in one of the comboboxes, the listIndex would be 1 because it starts at 0. A ListIndex of -1 indicates that noting has been selected. And setting the ListIndex to 0 via code should show the first item in the combobox.
5.    Is there code anywhere else in your project that refers to any of the comboboxes?
6.    Do you know how to use Debug?
0
GeekamoAuthor Commented:
@ MartinLiss,

1.)  Yes, the combo boxes are on the userform (named: RARequest)

ComboBox
2.)  Compiled?  I have no idea, so I think the answer is no.
3.)  I have 5 combo boxes.  The reference to AnimalComboBox, I should have changed when I pulled that example from Google - which explains that that piece didn't work.  But even after changing it to cboReason1, it still doesn't work.
4.)  I have no idea.  I think I got that code from Google, I would of tested it - nothing worked, so I just commented it out.
5.) Nope.
6.) Never used the debug before...

I have exported all of the vba code from Outlook. - See attached zip.  Hopefully, you'll be able to spot the issue right now.  On a side note - I have other issues with this same user form - technically my "Generate Email" button on the RA Request form, results in an error - but that's on a separate issue I haven't been able to troubleshoot yet.

Btw, there's extra files in the zip - that never import correctly.  Which is odd - because they are created from the export process - so I have no idea what that is all about. I just click OK on the two import errors.

~ Geekamo
MartinLiss.zip
0
Martin LissOlder than dirtCommented:
Regarding the compile issue, in Excel I would go into Visual Basic development and the click the Debug|Compile VBAProject menu item.
0
GeekamoAuthor Commented:
@ MartinLiss,

I clicked on the Debug/Compile - but nothing happened.  Should something have happened?

~ Geekamo
0
Martin LissOlder than dirtCommented:
Yes, if there were syntax errors.

I was sort of able to turn your project into a VB6 project and in that environment when I open the RARequest form and run this code
    With cboReason1
 .AddItem "Dog"
 .AddItem "Cat"
 .AddItem "Horse"
 .ListIndex = 0

 End With

'    cboReason1.RowSource = "Test 1"
    cboReason2.AddItem "Test 2"
    cboReason3.AddItem "Test 3"
    cboReason4.AddItem "Test 4"
    cboReason5.AddItem "Test 5"

Open in new window


the entries show up in the comboboxes as expected. Why do you have that code commented out?
0
Martin LissOlder than dirtCommented:
Replace your Userform_Initialize procedure in RARequest with this. What happens when you run it?


Private Sub userform_Initalize()

    cboReason1.Clear
    cboReason2.Clear
    cboReason3.Clear
    cboReason4.Clear
    cboReason5.Clear

    With cboReason1
        .AddItem 1
        .AddItem 2
    End With
    
    'lbEmails.Clear
    
    With cboReason1
 .AddItem "Dog"
 .AddItem "Cat"
 .AddItem "Horse"
 .ListIndex = 0

 End With

    'cboReason1.RowSource = "Test 1"
    cboReason2.AddItem "Test 2"
    cboReason3.AddItem "Test 3"
    cboReason4.AddItem "Test 4"
    cboReason5.AddItem "Test 5"
    
    
'    cboReason1.ListIndex = "Test 1"
'    cboReason2.ListIndex = "Test 2"
'    cboReason3.ListIndex = "Test 3"
'    cboReason4.ListIndex = "Test 4"
'    cboReason5.ListIndex = "Test 5"
    
    
'    lbEmails.AddItem "Sample Request"
'    lbEmails.AddItem "Quote Request"
'    lbEmails.AddItem "Return Authorization Request"
'    lbEmails.AddItem "Order Expedite Request"
    cboReason1.ListIndex = 0
    cboReason2.ListIndex = 0
    cboReason3.ListIndex = 0
    cboReason4.ListIndex = 0
    cboReason5.ListIndex = 0
    cboReason1.ListIndex = 0

    
End Sub

Open in new window

0
GeekamoAuthor Commented:
@ MartinLiss,

This is sooooo frustrating, still not working for me.
0
Martin LissOlder than dirtCommented:
Put a breakpoint on the first line of code in that procedure by clicking in the line's left hand margin and run the code. Dies the code get there?
0
GeekamoAuthor Commented:
By breakpoint, do you mean the RED DOT, along with the red highlighted row?  I setup 3 of those, ran code - nothing.  It just errors out, but only after I click generate email - but at that point, it's showing an error on a different sub (which I already know is an issue).

Being that I'm not sure if I did the breakpoint thing correctly, I also put in MSGBOX "test" as the first line of code to run - and I never see that message box come up.

So is this a matter of that entire sub never being triggered to run?
0
Martin LissOlder than dirtCommented:
Yes  that seems to be the logical conclusion. Does the form have an Activate event? If so as a first step but a breakpoint  (yes the red dot) on the first line of that procedure. Does the code get there?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GeekamoAuthor Commented:
Sweet Jesus!  That was it!

This is odd though, because initially I was using the activate - and it didn't work then.  But I'm sure there was also another issue in the mix.  Idk, I'm finally on the right path now!

Martin, I can't being to thank you enough in helping me troubleshoot this!  What a headache this all was!  Now, time to clean up all the code! (This time I'll be very careful of changes... :)

~ Geekamo
0
GeekamoAuthor Commented:
Just incase I have another issue, I'm going to leave this open.  The lists don't have the correct information, so I'm going to clean it up - add the correct info, and if the lists still work then GREAT!...
0
Martin LissOlder than dirtCommented:
Is there anything more that I can do for you in this question?
0
GeekamoAuthor Commented:
Thank you again Martin!  You've been so much help.  Appreciate it!
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.