Results 1 to 5 of 5
  1. #1
    svartisya is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    3

    multiselect listbox - search result problem


    Hello
    I have a search form with a multi-select listbox and a button that opens a continuous form with the search results.
    Here's the problem: when I select more than one item, the form shows all risults with one item OR another item, I need to search for all records that contain all the selected items. I need your help as I'm a noob with VBA

    This is the code I am using:
    Code:
    Private Sub Search_Click()
        
        Dim strSelection As String, varItem As Variant
        Dim strSQL As String
        For Each varItem In Me!ListbI.ItemsSelected
             strSelection = strSelection & Me!ListbI.ItemData(varItem) & ","
        Next varItem
        If Len(strSelection) = 0 Then
              MsgBox "Select at least one item!", vbExclamation, "Attention!"
              Exit Sub
       End If
       strSelection = Left(strSelection, Len(strSelection) - 1)
        strSQL = "IDIng IN (" & strSelection & ") "
       DoCmd.OpenForm "Filter", acNormal, , strSQL
       DoCmd.Close acForm, "Search"
    Exit_Search_Click:
       Exit Sub
    End Sub
    thank you

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Check out Allen Browne's code for this http://allenbrowne.com/ser-50.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    svartisya is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    3
    Thanks June7
    I tried Allen Browne's code, but I get exactly the same result as before.
    The code uses the OR operator, so if a record includes both items, my coninuous form shows this record twice. How can I avoid showing records more than one time?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I don't understand. How can a record have more than one value in same field, unless it is a multi-value field and I don't think this code would work with multi-value field?

    Show sample data.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    svartisya is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    3
    I think the problem is my query, I'm trying to fix it

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

Similar Threads

  1. Listbox multiselect status
    By Sam23 in forum Programming
    Replies: 5
    Last Post: 03-06-2012, 01:13 PM
  2. Search engine result database suggestions
    By PIHA520 in forum Access
    Replies: 0
    Last Post: 05-29-2011, 05:44 PM
  3. Append Records using MultiSelect Listbox
    By Ted C in forum Programming
    Replies: 14
    Last Post: 03-15-2011, 01:25 PM
  4. Binding a Combo Box Search Result
    By cvansickle in forum Forms
    Replies: 2
    Last Post: 12-06-2010, 11:03 AM
  5. Search result links adding extra info
    By Vbcw in forum Programming
    Replies: 0
    Last Post: 12-19-2008, 12:19 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