Results 1 to 4 of 4

Thread: Populating a list box from a recordset quickly

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Location
    Littlehampton, W Sussex GB
    Posts
    203

    Post

    I have a recordset containing several thousand records and am populating a list box for a search with
    data.recordset.movenext and list1.additem
    Is there a quicker way to do this with a large recordset as it takes a while on the network to populate the list box (up to 25 secs!!)
    Thanks

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    Are you hiding the control while populating it? This will consume less time as it doesn't have to do screen refreshes.

  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    If you are trying to populate a combobox with a hundred records or more, try rethinking your strategy. If you have to populate that combobox every time each person loads up that form, it will kill the network and, as you have seen, take forever to load. Your network admin will not be very happy with you.

    Tom

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Other things you can do to optimize the transfer are..
    Use an OpenForward Only Recordset and Reduce the Number of Object Branches,(Periods), being referenced, somthing like:
    Code:
    Private Sub Command1_Click()
        Dim oDb As Database
        Dim oRs As Recordset
        Set oDb = OpenDatabase("BIBLIO.MDB")
        Set oRs = oDb.OpenRecordset("SELECT Author FROM Authors", dbOpenForwardOnly)
        While Not oRs.EOF
            'In Some Cases, Referencing by the Field 'Name'
            'Can be faster than the Index No.
            List1.AddItem oRs(0)
            oRs.MoveNext
        Wend
        Set oRs = Nothing
        oDb.Close
        Set oDb = Nothing
    End Sub
    On my P200 this Populated Over 6,000 Records in a little over 2 Seconds.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

Posting Permissions

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



Click Here to Expand Forum to Full Width