Results 1 to 5 of 5
  1. #1
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112

    Need Multi-Select listbox code example

    Hi


    I've written some VBA code that reads the selections in a multi-select listbox and stores it into a table.

    However, I'm facing a problem. The form is a multi-record form, and the user can go forwards or backwards in the form.

    If he goes back, and he's already made a previous selection in the listbox which had already been stored in the tables, I want to restore his previous selections.

    Also I need to know if he makes new selections so that I can delete those he deselected from the listbox from the table, and add new ones into the table.

    I don't know how to do this efficiently. The best code example I found was this:

    http://www.rogersaccesslibrary.com/forum/topic331.html

    but it's too simplistic for what I need, because the table is very, very small. Mine can grow very large, and I don't have a boolean field that marks whether or not the item is selected. It's just stored into the table.

    Does anyone have any sample code that can show me how to do this?

    Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Build a delimited string with the items (open a recordset on your table and loop the items), then this type of thing:

    Code:
        For i = 0 To ctl.ListCount - 1
          SearchItem = ctl.ItemData(i) & ";"
          ctl.Selected(i) = (InStr(strSelected, SearchItem) > 0)
        Next i
    Where strSelected is the delimited string.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Thanks. I'll give it a try.

    In the sample code they tested for this condition in the loop, but I don't understand why.

    'If Not rs.BOF Then

    I assume BOF is the Beginning Of File marker, but why is this check necessary?

    Thanks.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Haven't looked at his code, but typically there are processes you only want to do if the recordset returns records, or the process includes code that would error on an empty recordset.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    ok thank you!

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

Similar Threads

  1. Replies: 7
    Last Post: 11-24-2014, 02:11 PM
  2. multi-select listbox and new entry button
    By user622 in forum Forms
    Replies: 2
    Last Post: 07-05-2011, 09:14 AM
  3. Replies: 3
    Last Post: 06-22-2011, 08:51 AM
  4. Multi select box with several options
    By float in forum Programming
    Replies: 7
    Last Post: 10-04-2010, 07:33 AM
  5. Multi-select listbox and update flag in table
    By Suresh in forum Programming
    Replies: 0
    Last Post: 12-19-2007, 01:04 AM

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