Results 1 to 2 of 2
  1. #1
    Vetgeorge is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29

    Multi Select List Box on a Search Form

    I've found helpful information about using a multi select list box on a search form from Martin Green (http://www.fontstuff.com/access/acctut11.htm). I have followed the instructions he has as far as code and it works in my database. However, the way his example works is that a query opens up in a separate window. I would like the query to open as a subform on my search form. What do I have to add/change in the code to do this? The query is called qryMultiSelect and I have tried inserting it as a subform and making it requery in the code, but that doesn't do anything, unless I am doing it wrong in having it as part of my on click event (OK button).



    Currently the code reads:
    Code:
    Option Compare Database
    Option Explicit
    Private Sub cmdOK_Click()
    ' Declare variables
        Dim db As DAO.Database
        Dim qdf As DAO.QueryDef
        Dim varItem As Variant
        Dim strCriteria As String
        Dim strSQL As String
    ' Get the database and stored query
        Set db = CurrentDb()
        Set qdf = db.QueryDefs("qryMultiSelect")
    ' Loop through the selected items in the list box and build a text string
        If Me!lstCategory.ItemsSelected.Count > 0 Then
            For Each varItem In Me!lstCategory.ItemsSelected
                strCriteria = strCriteria & "tblCombined.fldCategory = " & Chr(34) _
                              & Me!lstCategory.ItemData(varItem) & Chr(34) & "OR "
            Next varItem
            strCriteria = Left(strCriteria, Len(strCriteria) - 3)
        Else
            strCriteria = "tblCombined.fldCategory Like '*'"
        End If
    ' Build the new SQL statement incorporating the string
        strSQL = "SELECT * FROM tblCombined " & _
                 "WHERE " & strCriteria & ";"
    ' Apply the new SQL statement to the query
        qdf.SQL = strSQL
    ' Open the query
        DoCmd.OpenQuery "qryMultiSelect"
    ' Empty the memory
        Set db = Nothing
        Set qdf = Nothing
    End Sub
    .
    Click image for larger version. 

Name:	2013-09-28_194324.jpg 
Views:	33 
Size:	16.7 KB 
ID:	13913

  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,521
    I would set the subform's record source property to your SQL variable.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 07-26-2012, 12:59 PM
  2. Replies: 3
    Last Post: 03-10-2012, 06:15 PM
  3. 2 multi select list boxes on one search form
    By woodey2002 in forum Forms
    Replies: 2
    Last Post: 11-05-2010, 12:44 PM
  4. Replies: 1
    Last Post: 10-22-2010, 10:11 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