Geekamo
asked on
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?
Thank you in advance for your help!
~ Geekamo
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
Thank you in advance for your help!
~ Geekamo
ASKER
@ MartinLiss,
Hmm, something is wrong - received error. (I have no clue what I'm doing...)
~ Geekamo
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
~ Geekamo
Leave out the "Do" in line 18.
ASKER
@ MartinLiss,
That didn't work either.
~ Geekamo
That didn't work either.
~ Geekamo
Can you attach your wb then please?
ASKER
@ 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...
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
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?
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?
ASKER
@ MartinLiss,
1.) Yes, the combo boxes are on the userform (named: RARequest)
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
1.) Yes, the combo boxes are on the userform (named: RARequest)
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
Regarding the compile issue, in Excel I would go into Visual Basic development and the click the Debug|Compile VBAProject menu item.
ASKER
@ MartinLiss,
I clicked on the Debug/Compile - but nothing happened. Should something have happened?
~ Geekamo
I clicked on the Debug/Compile - but nothing happened. Should something have happened?
~ Geekamo
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
the entries show up in the comboboxes as expected. Why do you have that code commented out?
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"
the entries show up in the comboboxes as expected. Why do you have that code commented out?
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
ASKER
@ MartinLiss,
This is sooooo frustrating, still not working for me.
This is sooooo frustrating, still not working for me.
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?
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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!...
Is there anything more that I can do for you in this question?
ASKER
Thank you again Martin! You've been so much help. Appreciate it!
You're welcome and I'm glad I was able to help.
Marty - MVP 2009 to 2013
Marty - MVP 2009 to 2013
Do cboReason1.ListIndex = 0 for example in your code after you fill them.