Results 1 to 5 of 5

Thread: Combo Box question

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    48

    Post

    If you load a listbox or combo box in code instead of using a control, how come it takes sooooo long? I have 3000 records and even using the code with a recordcount instead of eof, it takes forever. Using a data control(DAO) pops right up. Any suggestions?

    Also, using MIDI child forms treats the forms differently when hiding and showing (As far as sometimes the activate event don't work when re-showing). Is MIDI child forms the best route in a programming project? Just curious.

  2. #2
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    As far as the MDI forms go, it's not necessarily the best way to go, it just depends on what you're trying to do and what kind of look you want it to have. Mostly that's personal preference. However, my personal opinion is that when making a professional-looking interface, you would probably want to use MDI forms, because it looks more like the professional software you would buy in a store. But it's really up to you.

    ------------------
    Ryan

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    There are a lot of ways to load a control. Please post your code and maybe we can help you speed it up.

    ------------------
    Marty

  4. #4
    New Member
    Join Date
    Jan 2000
    Location
    South Australia, Australia
    Posts
    1

    Post

    One solution is to use the DataCombo control in VB6.
    Use this routine to bind a DataCombo to an ADO recordset.

    *******************************************
    Public Sub FillDataCombo(c As DataCombo, _
    rsRecordSource As Recordset, _
    strListField As String, _
    strBoundColumn As String)
    ' Purpose : none
    ' Assumptions : nonoe
    ' Effects : none
    ' Inputs : DataCombo control,
    ' Recordset to fill the control with,
    ' String name of field to display in control
    ' String name of field to bind
    ' Returns : none

    Set c.RowSource = rsRecordSource
    c.ListField = strListField
    c.BoundColumn = strBoundColumn

    End Sub

    *******************************************


    I have the same problem as lambela8 when filling the regular combobox with many items, and the handy thing about the regular combo, is I can make it act like the combo in Access97.
    If anyone knows a very fast way to fill a normal combobox with the contents of a large ADO recordset, I would be happy to post the Access97 mimic control to useful replies.

    Scott

  5. #5
    Member
    Join Date
    Nov 1999
    Posts
    63

    Post

    Lambela8,

    The perceived speed of a combobox or any list/grid type control that is bound to a DAO data source is partially the result DAO being "hot wired" to fill the visible portion of the list control. This is best illustrated by trying a simple test. Create a test database that contains a table with a couple of columns named "Item" (Number data type) and "Desc" (Text data type). Then add one million records to the table using some code like the following to create the records.

    Code:
        Dim n As Long
        Dim db As Database
        Dim rs As Recordset
        
        Set db = DBEngine.Workspaces(0).OpenDatabase("db1.mdb")
        Set rs = db.OpenRecordset("TestTable")
    
        For n = 1 To 1000000
            rs.AddNew
            rs!Item = n
            rs!Desc = "Decscription Item " & n
            rs.Update
        Next
    Then start a new project and place a listbox and a data control on a form. Set the data control's database and recordsource properties to access the table in your test database and set its visible property to false. Then set the listbox's rowsource to the data control and set its listfield property to "Desc". Now run the application. You will see that the form and listbox are instantly displayed. Have all one million records actually been read from the table? The answer is no... not yet anyway. The data control is still feeding data to the listbox.

    Now close the project and reboot your computer to release any cached records from memory. Restart the project and as soon as the form is displayed press Ctrl+End to force the selection to the end of the list. You will now hear your hard drive bumping and grinding its way through all one million records. After a few moments the list will be refreshed.

    Now the above test is still pretty fast. Much faster than stepping through a recordset with movenext and using additem to fill your list control. However, if you were to try this test using ADO you may discover some rather disappointing if not frustrating results. I know I did!

    Gerald

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