Results 1 to 4 of 4
  1. #1
    JanGray is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    2

    Multiple Selection from 4 Form fields

    I've created a query that pulls parameters from a form and I need the user to be able to query by 1, 2, 3, or 4 separate criteria. Right now, the query seems to work fine with either 3 or 4 criteria selected but it doesn't work if fewer than 3 criteria are selected -- i.e., 2 or 3 of the combo boxes are left blank. How can I improve this query to make this work?

    Here's my query:



    SELECT tblDeliverables.ID, tblDeliverables.[Department/Owner], tblDeliverables.[Deliverable name], tblDeliverables.[Deliverable format], tblDeliverables.[Targeted roles], tblDeliverables.[Referenced products], tblDeliverables.[Clients/Components]
    FROM tblDeliverableFormat INNER JOIN (tblXPProducts INNER JOIN (tblXPClientsComponents INNER JOIN ((tblDeliverables INNER JOIN tblDepartments ON tblDeliverables.[Department/Owner] = tblDepartments.[Dept Code]) INNER JOIN tblPersonas ON tblDeliverables.[Targeted roles].Value = tblPersonas.[Targeted Role].Value) ON tblXPClientsComponents.Code = tblDeliverables.[Clients/Components].Value) ON (tblXPProducts.[Product Name] = tblXPClientsComponents.[XP Product(s)].Value) AND (tblXPProducts.[Product Code] = tblDeliverables.[Referenced products].Value)) ON tblDeliverableFormat.ID = tblDeliverables.[Deliverable format].Value
    WHERE (((tblDeliverables.[Department/Owner])=[Forms]![frm1TESTMultiSearchOptions]![cboSearchDept]) AND ((tblDeliverables.[Clients/Components].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboClient]) AND ((tblDeliverables.[Targeted roles].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboPersona]) AND ((tblDeliverables.[Referenced products].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboProduct])) OR (((tblDeliverables.[Department/Owner])=[Forms]![frm1TESTMultiSearchOptions]![cboSearchDept]) AND ((tblDeliverables.[Targeted roles].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboPersona]) AND ((tblDeliverables.[Referenced products].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboProduct])) OR (((tblDeliverables.[Department/Owner])=[Forms]![frm1TESTMultiSearchOptions]![cboSearchDept]) AND ((tblDeliverables.[Clients/Components].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboClient]) AND ((tblDeliverables.[Targeted roles].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboPersona])) OR (((tblDeliverables.[Department/Owner])=[Forms]![frm1TESTMultiSearchOptions]![cboSearchDept]) AND ((tblDeliverables.[Clients/Components].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboClient]) AND ((tblDeliverables.[Referenced products].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboProduct])) OR (((tblDeliverables.[Clients/Components].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboClient]) AND ((tblDeliverables.[Targeted roles].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboPersona]) AND ((tblDeliverables.[Referenced products].Value)=[Forms]![frm1TESTMultiSearchOptions]![cboProduct]));

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    make a query that shows all records.
    in a continuous form ,you have different controls to filter, when user clicks FIND button.

    build the 'where' clause by cycling thru all the controls....
    it executes after a find button CLICK event
    if null, ignore.
    if not, apply.


    Code:
    '----------------
    sub btnFilter_click()
    '----------------
    dim sWhere as string 
    
    
    sWhere = "1=1"
    if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
    if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
    if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
    
    
    If sWhere = "1=1" Then
      Me.FilterOn = False
    Else
      Me.Filter = sWhere
      Me.FilterOn = True
    End If
    end sub

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Change your AND operators that refer to the form controls to OR
    or
    write the sql in code by piecing together only the parameters that have been provided.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also see Use a parameter to return all records if Null
    Not my fav option but worth knowing about.

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

Similar Threads

  1. Replies: 20
    Last Post: 01-24-2021, 05:49 AM
  2. Replies: 9
    Last Post: 08-25-2014, 05:09 PM
  3. multiple selection in sub form
    By trevor40 in forum Programming
    Replies: 3
    Last Post: 03-01-2014, 01:38 PM
  4. Update Multiple Fields based on Selection (inTable)
    By aguestnga in forum Database Design
    Replies: 3
    Last Post: 11-03-2011, 04:17 PM
  5. Replies: 1
    Last Post: 11-11-2010, 11:00 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