Results 1 to 11 of 11
  1. #1
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413

    Listbox to Listbox move puzzle

    ListBoxParadox.zip



    For large selections, the move time from one listbox to the other varies greatly, depending on how the rows are selected. For example, if manual selection of all 10000 rows is made, the move (clicking the > or < ) will complete in about 5 seconds.
    However, if the selection is made via the 'Select All' button, not only will the selection take a long time, but now the move (< or >) will take at least 60 seconds instead of the previous 5 seconds. Both moves use the same code (the > button).
    Why would this be so?

    Click image for larger version. 

Name:	listboxes.png 
Views:	28 
Size:	28.0 KB 
ID:	50931
    Last edited by davegri; 10-22-2023 at 01:40 PM. Reason: elucidate

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I'd say it's because you're looping through 10K rows to select them, then probably looping over again to move them. Manually selecting them avoids the first loop. Just a theory. I suspect you're not looping over an array but over the controls instead (I mean their item lists). You might get a speed gain by copying selected items into an array. I'd also see if there's a faster way to create an array/collection/dictionary other than looping over the selected items when all are selected. Perhaps make the 2nd control bound to a query that returns everything instead.

    EDIT - going to leave my reply as is for now. I just noticed that you posted a db copy.
    Last edited by Micron; 10-22-2023 at 04:03 PM.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    So yeah, as long as the lists are not value lists I think I'd just set the controlsource property and let a query populate each control when moving the entire list.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by Micron View Post
    So yeah, as long as the lists are not value lists I think I'd just set the controlsource property and let a query populate each control when moving the entire list.
    I was doing it that way and it was VERY fast for even 65000 rows.

    However, that's not the answer that I am seeking. I'd like to know why the exact same code that moves the rows is 10 times faster when the source rows are selected manually versus selection by iterating code. You would think that once selected by either method, the move time would be equal. However, it is not.

    I ran into this behavior when developing and testing and am just curious if anyone knows why it might be so.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    All I have is the theory I posted. Putting that therory another way, 10K rows are already selected in a gui vs having to select them by looping over them in code. I suspect that pre-selecting has already put them into some sort of memory space, be that a collection or array or something similar. Code isn't part of the gui. (end of theory).

    On my laptop, the transfer process takes 72 seconds in case you're interested in performance elsewhere.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by Micron View Post
    All I have is the theory I posted. Putting that therory another way, 10K rows are already selected in a gui vs having to select them by looping over them in code. I suspect that pre-selecting has already put them into some sort of memory space, be that a collection or array or something similar. Code isn't part of the gui. (end of theory).
    That does seem plausible. Something is obviously different after the selections.

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Micron is correct. There are even comments in the code saying this will be slow over 3500 records.

    ' If fcnTooBig(LB_Left) Then
    ' If MsgBox("Selecting over 3500 rows may be too slow for your liking." & vbCrLf & vbCrLf _
    ' & "Instead of 'Select All', you can manually select fewer rows with multipe moves." & vbCrLf & vbCrLf _
    ' & "Do you want to continue with the large select?" _
    ' , vbQuestion + vbYesNo, " C O N T I N U E ?") = vbNo Then
    ' Exit Sub
    ' End If
    ' End If
    Looking at the code, the method used for selecting all is to loop through the listbox items and changing the selected property from false to true. Which as he says is going to be a lot slower that the GUI

    This looks like fairly old code you have got from somewhere. A better method is to use a datasheet subform and use sql. You would also have a separate table called say tblSelected and populate that with the record's PK. Your recordsource for the left form would then left join to that table - not null means selected, null means not selected. Datasheets don't quite have the same functionality as an extended multi select listbox although they can be programmed in, but they have other benefits - for example if you wanted to scroll down to the 'w's is easy with a datasheet, try doing that with the listbox.

    There are better ways to select from a table of 10,000 names if that is a requirement rather than just curiosity calling.

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Thanks to all for insights. I'll probably post an enhanced DB to the 'Sample Databases' forum soon with code that mostly avoids time consuming looping over the listboxes.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Here's a link to a youtube video on Moving To/From Listboxes This is a resurrection of an old video from Datapig Technologies.
    I added the link because Moves Listbox to/from Listbox is quite common. Will be watching for davegri's 'Sample Database'.

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by orange View Post
    Here's a link to a youtube video on Moving To/From Listboxes This is a resurrection of an old video from Datapig Technologies.
    I added the link because Moves Listbox to/from Listbox is quite common. Will be watching for davegri's 'Sample Database'.
    I remember the datapig website. Video tutorials from before YouTube had them all.
    My technique is somewhat like Mike Alexander's in that I use a Flag field in the table to determine which listbox (if either) to show the table rows.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Hi Dave,

    Here is a link to a thread where I mentioned the loss of DataPig Technologies videos. It is interesting because my initial concern was that DatabaseAnswers.org (variety of datamodels) was no longer online. Happy to say that we worked with Crystal Long/strive4peace to get the DataPig videos resurrected and hosted on her site.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-25-2017, 07:31 PM
  2. Replies: 2
    Last Post: 05-21-2014, 01:16 PM
  3. Listbox Scrollbar - Can I move it to the left?
    By mantooth29 in forum Forms
    Replies: 4
    Last Post: 04-11-2014, 02:29 PM
  4. Move Data from one listbox to another
    By WickidWe in forum Access
    Replies: 15
    Last Post: 12-16-2013, 08:25 PM
  5. Replies: 1
    Last Post: 09-10-2012, 11:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums