Forum Discussion
Combo Boxes not displaying Data
NikolinoDE Thank you for replying. I have tried all the above. Still no luck. I was wondering if it has to do with a bug in software? In that you can't have 2 forms open at once? The strange thing is, I tested the combo box by moving it to the first form, and it works fine. when I move it to the second form, I don't see the data. Any other ideas? Thanks.
guitar713 Having two userforms open at once shouldn't be a problem. Glitches can occur, though, especially with Excel for MS365. How exactly are you populating the combo box? Did you hard code the worksheet range directly in the RowSource property of the combo box? Did you define a name for the worksheet range, as shown in the example below?
Alternatively, you can also try leaving the RowSource property blank, then populate it on the fly in the UserForm_Initialize procedure. For example:
Private Sub UserForm_Initialize()
Me.ComboBox1.RowSource = "lstStatus"
End Sub
Or, by looping through the items in the range:
Private Sub UserForm_Initialize()
Dim rg As Range, i As Long
Set rg = Range("lstStatus")
For i = 1 To rg.Rows.Count
Me.ComboBox1.AddItem rg.Cells(i, 1).Value
Next i
End Sub
These are just a few basic examples. I've tested them all with two simple userforms (shown in the screenshot above) and did not have any issues. If you are still unable to get it to work, please consider sharing more details, such as the code you are using in the each of the userforms, especially the code that opens the second userform, as well as any code currently being used in the UserForm_Initialize procedure of the second userform.
- guitar713Mar 05, 2024Brass ContributorSo the way I am calling the second form is to double click on a text box. I use the following code:
----------------------------
Private Sub txtCURRENTPeoplesoft_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
frmPeopleSoft.Show vbModeless
frmPeopleSoft.Enabled = True
End Sub
----------------------------------
But when I put the code that you recommended into the form 2 as follows:
----------------------------------
Private Sub UserForm_Initialize()
frmPeopleSoft.Enabled = True
Me.ComboBox1.RowSource = "Table3"
End Sub
-----------------------------
then I run my code, I get the following error
Run-time error '380':
Could not set the RowSource property. Invalid property value.
Then when I click on the debug tool, it goes to
Private Sub txtCURRENTPeoplesoft_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
frmPeopleSoft.Show vbModeless ---- this one is hightlighted as errored???
If you can follow my logic, this is what is happening.
thanks.- guitar713Mar 05, 2024Brass ContributorI have tried to fill in the "RowSource" property as well in the properties dialog....
That did not work either... - djclementsMar 05, 2024Bronze Contributor
guitar713 The error message you're getting is a pretty good indication that "Table3" does not exist as a defined name in the workbook. To verify the name of the table you want to use as the RowSource, select any cell within the table, then go to the Table Design tab on the ribbon. Copy the Table Name and paste it into your code to ensure that it's spelled correctly.
- guitar713Mar 05, 2024Brass ContributorI just confirmed it,, I do have the correct table called out,,, so I was curious,, I tried to paste another group of cells I know works from Form 1 into the "RowSource" area,, and that one also did not work. I know it works in Form1 but not Form2, still no data is showing up.