List Box Not populating on first open of form

tbird123

New Member
Joined
Jan 27, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I have a user form with list box that is populated from a sheet in my workbook. However, when I click my button to run "Show_StatusForm" once and open the form, the list box will not populate. However, if I close the form and then reopen it with the same button, the list box will be populated. I don't understand why it will not populate the list box the first time I open the form.


This first section here is where I open the form and call my "listBoxReference" which populates the list box.

VBA Code:
Sub Show_StatusForm()
    frmCCRStatus.Show
    Call ListBoxReference
End Sub

This section here is my called sub to populate the list box.

VBA Code:
Sub ListBoxReference()

    Dim iRow_Open As Long
    
    'Find the last blank row
    iRow_Open = ThisWorkbook.Worksheets("Open_CCR").Range("A" & Rows.Count).End(xlUp).Row
    
    'Set Open list box reference
    frmCCRStatus.lstOpenCCR.ColumnCount = 16
    frmCCRStatus.lstOpenCCR.ColumnHeads = True
    
     frmCCRStatus.lstOpenCCR.RowSource = "Open_CCR!A2:O" & iRow_Open
    
    'If iRow_Open = 1 Then
     '   frmCCRStatus.lstOpenCCR.RowSource = "Open_CCR!A2:O2"
    'Else
    '    frmCCRStatus.lstOpenCCR.RowSource = "Open_CCR!A2:O" & iRow_Open
    'End If

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
It may just be the order in which you are doing things.

Except there is a reason not to I will place the code in ListBoxReference under the Userform_initialize module(or call it from within the initialize module)

and then my first code would simply be
VBA Code:
Sub Show_StatusForm()
    frmCCRStatus.Show
End Sub

The initialize code would run before the form is displayed(i.e form.show), so this should be fine
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top