Results 1 to 2 of 2
  1. #1
    nagiese is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Nashville, TN
    Posts
    43

    Question Filtering a query using a multi select list Box

    Good afternoon:



    I have not used VBA and I am a novice at creating forms in Access so I'm having difficulty with a form that I'm trying to put together. I am trying to build a form to use to filter the data in a query. My issue is that I have two multi select list boxes where I need to be able to select all or some of the items in each of the boxes and then have the query run based on the criteria selected on the form.

    I'm able to get the query to run if I limit the list box to only one selection, but if I enable the multi select to Extended and run the query it returns an empty record set.

    I apologize, but I'm not as tech savy/smart as most and I've not used VBA so I'm not able to translate someone else’s code to suite my purposes.

    I wanted to attached a copy of my database in order for you to see what I'm trying to accomplish. But I am unable to upload any files to this forum site, I keep getting an error message.


    Thank you in advance for all of your help.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    i assume you can't use a multi select with the query wizard. you might have to create a dynamic object in code.

    for instance, put a button on the form to run the query and do something like:
    Code:
    on error resume next
    
    docmd.DeleteObject acQuery, "qry"
    
    dim intcurrentrow as integer
    
    sql = "select * from table where "
    
    For intCurrentRow = 0 To me.listbox.ListCount - 1
            If me.listbox.Selected(intCurrentRow) Then 
                sql = sql & "field = '" & me.listbox.column(0, intcurrentrow) & "' or "
            end if
    next intcurrentrow
    
    sql = left(sql, len(sql) - 4)
    
    currentdb.createquerydef "qry", sql
    currentdb.querydefs.refresh
    currentdb.openquery "qry"

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

Similar Threads

  1. Replies: 8
    Last Post: 12-22-2010, 08:12 AM
  2. 2 multi select list boxes on one search form
    By woodey2002 in forum Forms
    Replies: 2
    Last Post: 11-05-2010, 12:44 PM
  3. Replies: 1
    Last Post: 10-22-2010, 10:11 AM
  4. Multi-select List Boxes
    By Rawb in forum Programming
    Replies: 6
    Last Post: 09-21-2010, 09:02 AM
  5. Replies: 1
    Last Post: 02-25-2009, 07:29 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