Results 1 to 8 of 8
  1. #1
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,044

    Would like to use fewer queries to get output

    Experts:

    I need some assistance with "streamlining" a query. Attached database includes the following objects:

    1. Table "T01_Billets" -- contains eight (8) fields (e.g., [Acct_BA_Off], [Acct_OB_Off], etc.) where values are either 0 or 1.
    2. Table "T01_StaffMembers" -- contains a Yes/No field
    3. Nine (9) queries

    Current process:
    - The first eight queries (prefix "Q1_" through "Q8_") are individual queries which output a count of their associated field in [T01_Billets]
    - Query "Q9_BilletsAuth_Onboard_TotalSum" then combines the output of the eight (8) queries into a single row/record and produces a "total sum" listed in "BA_Total" and "OB_Total"

    Here's what I need some help with:


    - Instead of using 8+1 queries, I'd like to reduce the number of required "input queries" (Q1-Q8).

    My question: How can I generate the output from "Q9" using fewer queries? Is there a way to get the same results via a single query (or maybe with 1 or 2 helper/input queries vs. 8 helper/input queries)?

    Thank you,
    EEH
    Attached Thumbnails Attached Thumbnails Current Output.JPG  
    Attached Files Attached Files

  2. #2
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,044
    Never mind... I figured it out using one and only one query.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Example-davegri-v01.zip
    I had spent a bit of time on this before the OP declared his own solution.
    However, since no solution is posted here's what I came up with.
    It uses a temp table, a bit of VBA and one final query.
    It requires a button or some method to call sub Looper.

    Click image for larger version. 

Name:	looper.png 
Views:	13 
Size:	7.9 KB 
ID:	40915

  5. #5
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,044
    Davegri:

    Thank you for posting your proposed solution. I posted my "Aggregate" query which doesn't require any additional VBA.

    However, I now need to further tweak the query to include a criteria from "T01_Staffmembers". That is, I'd like to modify the query and add a crteria where [T01_Staffmembers].[All_Onboard] = True.

    As illustrated in the picture below, adding the [All_Onboard] field and setting the criteria results in an error. W/o that field, the query executes w/o any issues (i.e., doesn't require helper queries nor VBA).

    My question: How can I include this field (value = true) w/o getting this error?

    Thank you,
    EEH
    Attached Thumbnails Attached Thumbnails AggregateQuery.JPG  
    Attached Files Attached Files

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Move All_OnBoard field to T00_JunctionTable_OBS. Then you won't need T01_StaffMembers in the query.
    I moved the field in my posted solution.
    Last edited by davegri; 02-15-2020 at 03:29 PM. Reason: clarif

  7. #7
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,044
    Davegri - this would be an issue in my actual database. I need the field "Onboard" to remain in T01_Staffmembers. Is there another way I can include it as an expression in the query?

  8. #8
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,044
    Davegri - see attached JPG... this gives me the option to include the field and add the criteria. Thanks for chiming in.
    Attached Thumbnails Attached Thumbnails Solution.JPG  

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

Similar Threads

  1. Replies: 6
    Last Post: 01-31-2020, 02:19 PM
  2. Look Up - show fewer options by matching criteria....?
    By synses in forum Database Design
    Replies: 3
    Last Post: 03-13-2017, 02:33 PM
  3. Replies: 1
    Last Post: 04-08-2016, 04:55 PM
  4. Cause of fewer records in results?
    By #1Newbie in forum Queries
    Replies: 4
    Last Post: 06-07-2013, 09:47 AM
  5. output of queries like to have rounded numbers
    By techexpressinc in forum Queries
    Replies: 5
    Last Post: 05-28-2009, 07:56 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