×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How do you populate a MSForms 2.0 listbox

How do you populate a MSForms 2.0 listbox

How do you populate a MSForms 2.0 listbox

(OP)
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

RE: How do you populate a MSForms 2.0 listbox

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.

RE: How do you populate a MSForms 2.0 listbox

(OP)
Thanks.  It works great now.  Also, found a copy of fm20.hlp, which explains alot.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close