Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you load data into a listbox on a new UserForm using VBA?

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
I have never used forms with VBA but am experienced in VB but what I would do in VB is not working in VBA.

I have a user-form called frmPrint with a listbox called lstReports.

From a separate procedure I call the form:
frmPrint.Show

I have a procedure in frmPrint:
Private Sub Form_Load()
'Load the ListBox with available reports...

lstReports.AddItem "Arrecap.xls"
lstReports.AddItem "Ar-Phy~2.xls"
lstReports.AddItem "Ar-Cli2.xls"
lstReports.AddItem "Trendd~1.xls"
lstReports.AddItem "Trendd~2.xls"
lstReports.AddItem "Arpaid.xls"
lstReports.AddItem "Payrchrg.xls"
lstReports.AddItem "Research.xls"
lstReports.AddItem "Ptrad.xls"

End Sub

This is apparently not the correct way to load the listbox because nothing is happening...

I have read about loading the list box from a spreadsheet data range(ControlSource), but I do not want to use that method.

Thanks for any suggestions.
 
Your code works fine for me in Excel 2000 and Word 2000 with one minor adjustment. There isn't a

Code:
Private Sub UserForm_Load()

Try

Code:
Private Sub UserForm_Initialize()

ListBox1.AddItem "Arrecap.xls"
ListBox1.AddItem "Ar-Phy~2.xls"
ListBox1.AddItem "Ar-Cli2.xls"
ListBox1.AddItem "Trendd~1.xls"
ListBox1.AddItem "Trendd~2.xls"
ListBox1.AddItem "Arpaid.xls"
ListBox1.AddItem "Payrchrg.xls"
ListBox1.AddItem "Research.xls"
ListBox1.AddItem "Ptrad.xls"

End Sub


Dave
 
That's the ticket!!! Thanks for the tip!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top