Forum Discussion
Combo Box dynamic code not working
guitar713 It looks like you added Sheet4 to Rows.Count, as suggested, but missed my second suggestion of using the Worksheet.Range.Address property to set the RowSource. Change the highlighted line of code shown in your screenshot to the following:
Me.cmbCARRYREASON.RowSource = Sheet4.Range("Dynamic").Address(External:=True)
Personally, I would use the alternative method shown in my previous reply, setting the List property instead of the RowSource, but that's just me.
djclements Ild like to thank you for guidance on this program. What I am very confused with is how the references work with the forms and spreadsheets, how it pulls in the data from the excel files and puts them into the forms. This has been and continues to be problematic with this project. Again, I am having problems with the lstDatabase in module mdDataentry. let me know why this works in another project that I pulled this from and not in this one... when I change the wording to what you see in the file I sent you, sometimes it works and other times it does not work. Very confused. Can you help some more and set me on a road to know how to reference the files to fill in the database at the bottom of the form... and FYI, I want to use the REQUEST FORM_GATE1 to get my data from to populate the database in the form. Thank you very much.
- guitar713Apr 11, 2024Brass ContributorI wanted to add the problem can be found by hitting the "RESET" button
- djclementsApr 13, 2024Bronze Contributor
guitar713 Again, the majority of the problems you're experiencing are due to the application window being hidden. Setting the RowSource property of a List Box or Combo Box when the workbook is hidden is not as simple as it is when the workbook is visible. In the Reset_Form sub routine, try using the same Worksheet.Range.Address method I outlined in my previous replies, with the optional [External] argument set to True:
Sub Reset_Form() Dim irow As Long With frmDataEntry 'assigning rowsource to lstDatabase listbox .lstDatabase.ColumnCount = 12 .lstDatabase.ColumnHeads = True .lstDatabase.ColumnWidths = "40,80,80,40,45,70,80,0,0,0,0" ' identify the last non-blank row in database sheet irow = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row If irow > 9 Then .lstDatabase.RowSource = Sheet1.Range("A9:L" & irow).Address(External:=True) Else .lstDatabase.RowSource = Sheet1.Range("A9:L9").Address(External:=True) End If End With End Sub
Note: I changed the starting row in the above code from 2 to 9 because that's the row in your worksheet where the database starts. Also, some of your headers in row 9 (column A, B and C) have been merged with cells in row 8 (using Merge & Center)... this will have an undesirable affect to the appearance of the List Box, since you've set the ColumnHeads property to True. You should "unmerge" those cells and put the column headers in row 9 only.
You could save yourself a lot of headaches by leaving the workbook visible. The same effect that you're going for could be achieved through alternative means. For example, you could designate a single worksheet to be the "landing page" or "navigation page" when the workbook is opened, and every other worksheet could have their Visible property set to xlSheetVeryHidden (so they cannot be unhidden manually by the user). The "navigation page" worksheet could easily be designed just like your current UserForm1, with a button to launch the frmDataEntry user form. This would allow you to keep the workbook visible while hiding all of the other worksheets. Just a thought...
- guitar713Apr 13, 2024Brass Contributorafter playing with this, I figured out another method,,, similar to a refresh,, when reseting the form, I make it visible for a brief time, then rehide,,, it flashes briefly in background, but not so annoying.