UserForm Listbox Not Displaying

vthokienj

Board Regular
Joined
Aug 1, 2011
Messages
105
Office Version
  1. 365
Platform
  1. Windows
On a userform, I have a listbox. What I do not understand is why values do not write to the listbox if called from an external module.

A command button on the userform calls a sub that adds text. This text displays. Another sub is called by a module that also writes text, but this text never appears in the listbox.

Both code sections are being called and the listbox is not being cleared anywhere.

What explains this behavior? Thanks

' listbox is populated after calling
Code:
Private Sub btnPopulateListbox_Click()
    listboxTest.AddItem "written after button press on form"
End Sub
' listbox is blank after calling
Code:
Public Sub PopulateListboxFromModule()
    listboxTest.AddItem "written after called by module"
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
The Sub from your standard module should generate an object required error as you have not specified the userform on which the listbox is created.

Do you have error handling code as well by any chance, or something daft like "on error resume next"?

Anyway, the solution is fairly straightforward


Code:
Public Sub PopulateListboxFromModule()
 [COLOR=Red]userformname[/COLOR].listboxTest.AddItem "written after called by module" 
End Sub
 
Upvote 0
Thank you for the quick reply.

The problem persists even with specifying the form name.

Code:
Public Sub PopulateListboxFromModule()
    formMyForm.listboxTest.AddItem "written after called by module"
End Sub
 
Upvote 0
"Another sub is called by a module that also writes text, but this text never appears in the listbox."

What other sub is called by what module? Does the userform exist at that time?
 
Upvote 0
The second of the two function is what I was referring to.

Anyway this is solved by passing an instance of the instantiated userform to the function and calling the listbox property of that.

Thanks for the replies.
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,391
Members
452,909
Latest member
VickiS

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