Consulting

Results 1 to 4 of 4

Thread: Addling to a multi column listbox with VBA

  1. #1
    VBAX Newbie
    Joined
    Jun 2005
    Posts
    4
    Location

    Solved: Addling to a multi column listbox with VBA

    I have built a form that allows a user to search a data sheet, and display the results in a listbox, however I am having a bit of trouble getting the results to display in the best way.

    The results from the search a poplulated into an array which I then can populate the listbox with by using:
    lstResults.list = arrSites.

    However the array has empty rows at the end, so the list box is populated with empty data after the first few records.

    I have tried to use the .Additem method instead, but I do not know how to use this for a multi column listbox (Site Name, Site ID, State etc.)

    Should I just be happy I have the results showing, and ignore the empty rows, or is there some other way to populate the listing?

    Sean
    Last edited by Sean_OL; 07-14-2005 at 08:04 AM. Reason: Problem Solved

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Sean_OL
    I have built a form that allows a user to search a data sheet, and display the results in a listbox, however I am having a bit of trouble getting the results to display in the best way.

    The results from the search a poplulated into an array which I then can populate the listbox with by using:
    lstResults.list = arrSites.

    However the array has empty rows at the end, so the list box is populated with empty data after the first few records.

    I have tried to use the .Additem method instead, but I do not know how to use this for a multi column listbox (Site Name, Site ID, State etc.)

    Should I just be happy I have the results showing, and ignore the empty rows, or is there some other way to populate the listing?

    Sean
    An example

    Dim ary, i, j
    ary = [{"Bob","M", 123;"Lynne","F",898;"Amy","F",543}]
    With ListBox1
            For i = 1 To 3
                .AddItem ary(i, 1)
                For j = 2 To 3
                    .List(.ListCount - 1, j - 1) = ary(i, j)
                Next j
            Next i
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Jun 2005
    Posts
    4
    Location
    That is exactly what I needed, thanks a million.

  4. #4
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    Quote Originally Posted by xld
    An example

    Dim ary, i, j
    ary = [{"Bob","M", 123;"Lynne","F",898;"Amy","F",543}]
    With ListBox1
    For i = 1 To 3
    .AddItem ary(i, 1)
    For j = 2 To 3
    .List(.ListCount - 1, j - 1) = ary(i, j)
    Next j
    Next i
    End With
    Great!
    I never thought of adding manually by code..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •