Results 1 to 4 of 4
  1. #1
    Vonblack is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    2

    Trying to create a multiple select on same field

    Hi all,

    So.... my many attempts at creating a multiple select parameter field to have failed.

    I have however stumbled access query criteria which will enable me to create 4-5 combo boxes from the same field (e.g. select1, Select2, Select3, Select4 etc...) which when passed to my query will show the relevant records for each selection (See below).

    In ([Forms]![FormName]![Select1],[Forms]![FormName]![Select2],[Forms]![FormName]![Select3],[Forms]![FormName]![Select4])

    What I cannot work out is how to show all records if I leave my combo box's blank.

    I've tried the below which do not work...

    Like "*" and In ([Forms]![FormName]![Select1],[Forms]![FormName]![Select2],[Forms]![FormName]![Select3],[Forms]![FormName]![Select4])

    In ([Forms]![FormName]![Select1],[Forms]![FormName]![Select2],[Forms]![FormName]![Select3],[Forms]![FormName]![Select4]) and "*"

    In ([Forms]![FormName]![Select1],[Forms]![FormName]![Select2],[Forms]![FormName]![Select3],[Forms]![FormName]![Select4]) or "*"


    Kind Regards
    Steve

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Use VBA to build and apply filter. Review http://allenbrowne.com/ser-62.html.

    A multi-select listbox could be used instead of 4 comboboxes.
    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
    Vonblack is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    2
    Thanks June7...

    I think ive managed to replicate and sort it from this website (http://www.baldyweb.com/multiselect.htm) - Thanks to Baldy

    My query now uses a combination of traditional text boxes for single parameters. These are referenced in the query using the normal method i.e "=Forms]![FormName]![Select1]"

    With a list box that passes my multi select parameters directly when the report opens rather than through the query.

    i.e..

    Private Sub cmdOpenReport_Click()


    On Error GoTo Err_cmdOpenReport_Click


    Dim strWhere As String
    Dim ctl As Control
    Dim varItem As Variant


    'make sure a selection has been made
    If Me.lstEmployees.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 status"
    Exit Sub
    End If


    'add selected values to string
    Set ctl = Me.lstEmployees
    For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & ctl.ItemData(varItem) & ","
    Next varItem
    'trim trailing comma
    strWhere = Left(strWhere, Len(strWhere) - 1)
    'open the report, restricted to the selected items
    DoCmd.OpenReport "rptEmployees", acPreview, , "ID IN(" & strWhere & ")"


    Exit_cmdOpenReport_Click:
    Exit Sub


    Err_cmdOpenReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdOpenReport_Click




    End Sub

  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,652
    Post 3 was moderated, I'm posting to trigger email notifications.
    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: 2
    Last Post: 03-16-2016, 09:55 AM
  2. Replies: 2
    Last Post: 09-03-2013, 06:00 AM
  3. Replies: 7
    Last Post: 10-16-2012, 06:43 PM
  4. Create filter for multiple field search
    By luvsmel in forum Forms
    Replies: 5
    Last Post: 01-02-2012, 11:12 PM
  5. Replies: 0
    Last Post: 02-28-2011, 09:46 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