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 derfloh 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 populate a MSForms 2.0 listbox

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
Using Access 2000

I want to populate (via the OnOpen event of the form) a Microsoft Forms 2.0 listbox. The property sheet of this ActiveX control indicates I can have more than 1 column (via the ColumnCount property) and show and hide columns (via the ColumnWidth property). However, I don't know the syntax for adding a multiple column listbox. The following function (abc) works fine. However, function (def) does not work. How do I add the other column via the AddItem method?

NOTE: For these functions to work, you will need to select the Microsoft Access 2.0 listbox via the Insert ActiveX control menu and insert it onto a form. Then name the listbox "lstFrom".

Function abc()

Dim tdf As AccessObject

For Each tdf In CurrentData.AllTables
lstFrom.AddItem tdf.Name
Next tdf

End Function

Function def()

Dim tdf As AccessObject
Dim i as integer

i = 0
For Each tdf In CurrentData.AllTables
i = i+1
lstFrom.AddItem tdf.Name, i 'Incorrect syntax. What's the correct syntax?
Next tdf

End Functin
 
The second argument in AddItem is for the position in the list, not the column. Thus, both functions are essentially trying to do the same thing. By leaving i out in abc(), you're telling the function to put the item at the end of the list by default. The list starts at position 0, so, in def(), you're telling it to put the new item one slot beyond the last position.

Try incrementing i after adding the item. Use either Column or List property to add the extra columns. Remember, the rows and columns start with 0.

lstFrom.List(i, <column>) = <value>
or
lstFrom.Column(<column>, i) = <value>

This should set your columns for you. You can look these up in Help for more info. If you have a problem with the size, set the width of each column and the width of the control. You can also set the number of rows that it shows.
 
Thanks. It works great now. Also, found a copy of fm20.hlp, which explains alot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top