Results 1 to 2 of 2
  1. #1
    mesba713 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2015
    Posts
    5

    Query form with multiple Checkbox


    Hi Everyone,
    i have a newbie question and would appreciate every help.
    I have a form that runs a query. The query is based on one single table.
    In this table there are several Projects.(Project 1, Project2,Project3....etc)

    In the form there are several checkboxes, where the user can choose which projects he wants to chek. the thing is with my code if i check 2 projects he shows only the records where both projects are selected in the table. But the I want it to show all the records where either of them is shown.
    Ex. If i chech the boxes for Project1 and the checkbox for Project2 it should show the records where Project 1 is checked and also the records where Project 2 are also checked.


    Code:
        SELECT Vergabeumfang.S63T4, *
    FROM Vergabeumfang
    WHERE (
     
              ((Vergabeumfang.VSS_LAW) Like "*" & [Forms]![Vergabeumfang]![VSS_LAW_Box] & "*" Or (Vergabeumfang.VSS_LAW) Is Null) 
     
    And ((IIf([Forms]![Vergabeumfang]![S63T4_box]=-1,([Vergabeumfang].[S63T4])=True,([Vergabeumfang].[S63T4])=False or ((Vergabeumfang.[S63T4])=True ))))
     
     
    And ((IIf([Forms]![Vergabeumfang]![S63T2_box]=-1,([Vergabeumfang].[S63T2])=True,([Vergabeumfang].[S63T2])=False or ((Vergabeumfang.[S63T2])=True ))))
     
     
    AND ((Vergabeumfang.V_Commodity_Name) Like "*" & [Forms]![Vergabeumfang]![Commodity_Name_Box] & "*" Or (Vergabeumfang.V_Commodity_Name) Is Null) 
     
    ;

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You cant use form boxes in a query if there's nothing in them..so..
    Test all controls for a possible filter then build the sql via code.
    on btnFind_Click()...

    Code:
    dim sSql as string, sWhere as string
    
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
    
        'remove 1st And
    sWhere= mid(sWhere,4)
    
    sSql = "SELECT * FROM tblCompany WHERE " & sWhere
    
    frmResults.Recordsource = sSql

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

Similar Threads

  1. Replies: 1
    Last Post: 11-26-2014, 02:30 PM
  2. Query Based on Form Checkbox
    By tylerpickering in forum Queries
    Replies: 4
    Last Post: 11-11-2014, 09:32 AM
  3. Replies: 9
    Last Post: 01-03-2013, 04:04 PM
  4. Multiple checkbox filtering & Clearing
    By Havvix in forum Access
    Replies: 3
    Last Post: 12-05-2012, 04:42 PM
  5. Form Checkbox Query
    By rlsublime in forum Access
    Replies: 1
    Last Post: 03-12-2012, 12:10 PM

Tags for this Thread

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