Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193

    Hi Minty

    Thanks for your input. I'll keep plugging away.


    Quote Originally Posted by Minty View Post
    It's one of the reasons that sometimes it is easier to use VBA to build the exact filter/criteria you want rather than making a massive "Query of Doom" covering all the possibilities.
    I would think that using VBA would be just as complicated because I would have to check the state of each of the check boxes every time one is clicked, and then refresh the form display.

  2. #17
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Thanks CJ.

    That's where I'm getting confused. So, basically every time I introduce a new checkbox, I need to add another criteria to to the each of the existing fields?

  3. #18
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    yes - any combination of 3 checkboxes - 7? possible options. 4 checkboxes - 14? possible options

    You can make the query grid simpler by putting brackets around the total criteria e.g.

    (tbldrils.cameraunit=[Forms]![frmdrils]![camera] Or [Forms]![frmdrils]![camera] Is Null)

    but the query grid will still show it differently to how you wrote it, however probably easier to add additional criteria if you follow the same syntax

  4. #19
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Thanks CJ. I'll give that a try. It's the visualisation of the grid that is throwing me, so this could be a great help.

  5. #20
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    Think of ands and ors as maths functions - you need to be clear what is actually required. In maths

    2*12+1=what? (2*12) + 1 =25 or 2*(12+1)=26?

    Maths will default to the former - multiplication/division before adding/subtracting, but you can force the alternative by using brackets

    With coding you only ever determine a comparison as true or false, there isn't a maybe. Either a value = another value or it doesn't. or it is greater than another value, or it isn't, etc.

    So you need to identify your OR's as between brackets (in this case) to separate from the AND'S. You can do it the other way (A=true AND b=true) OR c=true when appropriate

    Learning to write sql directly simplifies a lot of things - no repeating of table name when not required, reduction in brackets and square brackets. So for example the sql generated by the query grid looks like this

    Code:
    SELECT tbldrils.ID, tbldrils.drillhead, tbldrils.cameraunit, tbldrils.mistunit, tbldrils.Notes
    FROM tbldrils
    WHERE (((([tbldrils].[cameraunit])=[Forms]![frmdrils]![camera] Or [Forms]![frmdrils]![camera] Is Null)<>False) AND ((([tbldrils].[mistunit])=[Forms]![frmdrils]![mist] Or [Forms]![frmdrils]![mist] Is Null)<>False) AND ((([drillhead] Is Not Null)=[Forms]![frmdrils]![drill] Or [Forms]![frmdrils]![drill] Is Null)<>False));
    It can be simplified to



    Code:
    SELECT ID, drillhead, cameraunit, mistunit, Notes
    FROM tbldrils
    WHERE (cameraunit=Forms!frmdrils!camera Or Forms!frmdrils!camera Is Null) 
               AND (mistunit=Forms!frmdrils!mist Or Forms!frmdrils!mist Is Null) 
               AND ((drillhead Is Not Null)=Forms!frmdrils!drill Or Forms!frmdrils!drill Is Null)

  6. #21
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Thanks again CJ for your explanation.

    I think I'll rework the whole lot writing the SQL directly. It certainly does look a lot easier to follow.

    I'll let you know how I end up.

  7. #22
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Hi CJ

    I think I have success!

    Your comment

    Learning to write sql directly simplifies a lot of things - no repeating of table name when not required, reduction in brackets and square brackets.
    is certainly true. This is way easier to understand, and easier on the eyes.

    Code:
    SELECT tbldrils.ID, tbldrils.drillhead, tbldrils.cameraunit, tbldrils.mistunit, tbldrils.Notes, tbldrils.airassist, tbldrils.pins
    
    FROM tbldrils
    
    WHERE (cameraunit=Forms!frmdrils!camera Or Forms!frmdrils!camera IsNull) 
    
    AND (mistunit=Forms!frmdrils!mist Or Forms!frmdrils!mist IsNull) 
    AND (airassist=Forms!frmdrils!airassist Or Forms!frmdrils!airassist isNull)
    AND (pins=Forms!frmdrils!pins Or Forms!frmdrils!pins isNull)
    AND ((drillhead IsNotNull)=Forms!frmdrils!drill Or Forms!frmdrils!drill IsNull);
    I've attached the DB if you want a look, just in case I've missed something.

    Drills-SQL.zip

  8. #23
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    Looks OK to me -

  9. #24
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Hi CJ
    Thank you again for your time and patience. This has been a great learning exercise for me. I really appreciate your input and guidance.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Set Triple State Toggle button values
    By mlrucci in forum Forms
    Replies: 3
    Last Post: 01-14-2022, 08:07 PM
  2. Triple Combo-Box Filter
    By BusDriver3 in forum Forms
    Replies: 12
    Last Post: 08-18-2016, 10:54 AM
  3. Displaying results of query in form text boxs
    By mgillespie21234 in forum Queries
    Replies: 3
    Last Post: 08-08-2015, 09:36 AM
  4. how to add tick boxs to filter
    By sspreyer in forum Programming
    Replies: 1
    Last Post: 11-05-2013, 09:13 AM
  5. Triple State checkbox scroll order
    By lfox in forum Forms
    Replies: 7
    Last Post: 06-26-2010, 08:19 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