Results 1 to 2 of 2
  1. #1
    Gee is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Posts
    31

    Query from Multiple List Boxes

    I'm trying a different angle.
    Say a user clicks 2 selections in Manub (a multi choice list box to choose a manufacturer) and 3 selections in Segub (another multi choice list box to choose the Seg. Only the Segs with the Manufacturer chosen show up in the Segub list box). I need to then run a query that has the data for all rows which includes those Manufacturers and Segs.
    Both are unbound listboxes.
    I added a button to run "CascadeQry" and put
    [Forms]![CascadeModelFrm]![Manub] in the Manufacturer Criteria of the Query and
    [Forms]![CascadeModelFrm]![Segub] in the Seg Criteria of the Query.


    It is returning a blank.

    Any suggestions?

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    First you must understand how a multiselect listbox works. There is a property called ItemsSelected that refers to a VBA collection. Rather than try to describe it myself here is the official blurb.

    ---
    The ItemsSelected collection is unlike other collections in that it is a collection of Variants rather than of objects. Each Variant is an integer index referring to a selected row in a list box or combo box.
    Use the ItemsSelected collection in conjunction with the Column property or the ItemData property to retrieve data from selected rows in a list box or combo box. You can list the ItemsSelected collection by using the For Each...Next statement.

    ---

    To interpret, this means that there is collection of row numbers that have been selected. You now have to examine each of the selected rows and extract the data value you want. In your case this will be a key to a manufacturer or a seg (whatever that is). Usually you set up a listbox with the primary key in column 0 but hidden.

    As you retrieve each primary key you must insert it into a comma delimited string suitable for use with the SQL 'In' construct. Here's an example of a typical SQL 'Where' clause:

    ... Where Manub In(123,456,789) And Seg In(34,65,89) ...

    Obviously all this extraction and formatting has to be done in VBA. Are you comfortable with VBA?

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

Similar Threads

  1. Replies: 3
    Last Post: 02-12-2013, 11:26 AM
  2. Replies: 8
    Last Post: 05-16-2012, 09:30 AM
  3. Replies: 3
    Last Post: 11-26-2010, 12:38 PM
  4. List box to populate other list boxes
    By Nathan in forum Forms
    Replies: 0
    Last Post: 03-03-2009, 07:22 PM
  5. Replies: 1
    Last Post: 03-01-2009, 09:53 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