Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Exclude grouped Schools if one of their bookings is unconfirmed

    I have a list of schools with many bookings



    However if one of their bookings are unconfirmed I don't want them to show

    So I want them to show if they have a booking confirmed however I don't want them to show if one of those bookings (say 1 out of 5) is unconfirmed.

    I have an iif field that if status was 2 or 3 (meaning unconfirmed) then show the school and because I am using grouped I don't get double records of the same school. I don't need to see the bookings, just the school name.

    This works well to show schools that have confirmed and unconfirmed however I want a second query list that shows only schools with all bookings confirmed and excludes any schools that happen to have one booking that is unconfirmed.


  2. #2
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119
    What is your structure like? Assuming you have schools in one table, and their bookings in a separate one, you can use a SELECT QUERY with a Count aggregation.

    Something similar to:
    Code:
    SELECT SchoolID, Count(BookingID) AS CountOfUnconfirmed
    FROM tblSchools LEFT JOIN tblBookings ON tblSchools.SchoolID = tblBookings.SchoolID
    WHERE BookingStatus IN (2,3)
    GROUP BY SchoolID
    HAVING Count(BookingID)=0

  3. #3
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    you must exclude all records of the school where there is one unconfirm - - before grouping. so you need a 'pre-query' (or queries) that accomplishes establishing the correct baseline record set before you do the aggregate query of grouping.... that pre-query would be along the lines of first finding all with an unconfirm, and then a no-match type query against those....I could imagine at least 2 queries to set up the baseline record set before doing the aggregate grouping query.....

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by NTC View Post
    you must exclude all records of the school where there is one unconfirm - - before grouping. so you need a 'pre-query' (or queries) that accomplishes establishing the correct baseline record set before you do the aggregate query of grouping.... that pre-query would be along the lines of first finding all with an unconfirm, and then a no-match type query against those....I could imagine at least 2 queries to set up the baseline record set before doing the aggregate grouping query.....
    Yeah two queries, then one with both and where one matches the other it is excluded. I end up with two queries. The problem I have is I can't import the query with the prequery inside into a recordset because I get a parameter error because I'm not running the first query in VBA first.

    Not sure how to get around that.

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    This would be the string of that Query with the prequery

    However this won't work and if I want it to stay strictly a string I have no idea how to write it because I'd rather work without saved queries
    Code:
    strSQLConfirmed = "SELECT qry_EOY_ConfirmedInWriting.NewSchoolsID, qry_EOY_ConfirmedInWriting.SchoolName, qry_EOY_NotConfirmed.Email " & vbCrLf & _
    "FROM qry_EOY_ConfirmedInWriting LEFT JOIN qry_EOY_NotConfirmed ON qry_EOY_ConfirmedInWriting.NewSchoolsID = qry_EOY_NotConfirmed.NewSchoolsID " & vbCrLf & _
    "WHERE (((qry_EOY_NotConfirmed.NewSchoolsID) Is Null)) " & vbCrLf & _
    "ORDER BY qry_EOY_ConfirmedInWriting.SchoolName;"

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Maybe like:

    SELECT DISTINCT SchoolID FROM bookings WHERE NOT SchoolID IN (SELECT DISTINCT SchoolID FROM bookings WHERE confirmed = False);
    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.

  7. #7
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Maybe like:

    SELECT DISTINCT SchoolID FROM bookings WHERE NOT SchoolID IN (SELECT DISTINCT SchoolID FROM bookings WHERE confirmed = False);
    I don't quite understand....

    The schools that have both confirmed and unconfirmed need to be emailed, however those who have all confirmed need to be separated. Two lists basically.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    That gives you the list of schools that have only confirmations, no unconfirmed.

    A query for the opposite would remove the NOT qualifier.

    Two lists.

    Open recordsets and loop through records to send individual emails or build one long addressees string.
    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.

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    That gives you the list of schools that have only confirmations, no unconfirmed.

    A query for the opposite would remove the NOT qualifier.

    Two lists.

    Open recordsets and loop through records to send individual emails or build one long addressees string.
    Yes, separate emails. The ones with unconfirmed get a second PDF for them to sign.

    I will give distinct a try - I am pulling bookings for each school, some with status confirmed and some with status unconfirmed and some with both confirmed & unconfirmed.

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    That gives you the list of schools that have only confirmations, no unconfirmed.

    A query for the opposite would remove the NOT qualifier.

    Two lists.

    Open recordsets and loop through records to send individual emails or build one long addressees string.
    I thought about doing that, if I loop through each school though just to check if they have an unconfirmed that's a lot of work, I wanted two quick recordsets and go with either.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    I am confused. Why would you have to check if they have an unconfirmed? That's already been done in the two queries. The process would be:

    1. open all confirmed query recordset, loop through records, send email(s)

    2. open non-confirmed query recordset, loop through records, send email(s)
    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.

  12. #12
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    I am confused. Why would you have to check if they have an unconfirmed? That's already been done in the two queries. The process would be:

    2. open non-confirmed query recordset, loop through records, send email(s)

    This recordset may contain schools from 1. unless they are excluded. That is why I used a prequery - then any matching ID is excluded.

    This works fine when you open a query and pull in two other queries, join the IDs and you get a query that lists only what you want.

    However I try to pull this in as a string for dao.recordset vba stuff and I get parameter errors because of the prequery.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    No school should be in both recordsets.

    1. query has only schools where ALL bookings are confirmed

    2. query has only schools where ANY booking is unconfirmed

    Your original query had all schools with an identifier that indicated if there was an unconfirmed booking. My two queries separate them and allow you to send different emails. Do you still want to send email 1 to schools that have confirmed bookings even though they also have unconfirmed?

    I don't really understand issue with 'prequery'. Should be able to open a recordset based on a query with nested subquery.
    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.

  14. #14
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    No school should be in both recordsets.

    1. query has only schools where ALL bookings are confirmed

    2. query has only schools where ANY booking is unconfirmed

    Your original query had all schools with an identifier that indicated if there was an unconfirmed booking. My two queries separate them and allow you to send different emails. Do you still want to send email 1 to schools that have confirmed bookings even though they also have unconfirmed?

    I don't really understand issue with 'prequery'. Should be able to open a recordset based on a query with nested subquery.
    The dao.recordset in vba would rely on either a string currentdb.openrecordset(string)

    however if I build a string like in post 5 I am using queries. I want to remove saved queries, have a string but at the same time have prequeries in that string

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Sorry, I am lost.

    If 'prequery' means a nested subquery, I don't understand why that is an issue. The queries I suggested work for me as source for recordset.
    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.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Exclude IDs in grouped query
    By Ruegen in forum Queries
    Replies: 2
    Last Post: 09-02-2014, 09:27 PM
  2. Bookings
    By teza2k06 in forum Sample Databases
    Replies: 1
    Last Post: 03-13-2013, 08:30 PM
  3. Sum bookings by quarter
    By kgav1 in forum Access
    Replies: 3
    Last Post: 04-14-2010, 08:15 PM
  4. Prevent Multiple bookings
    By Rory898 in forum Forms
    Replies: 2
    Last Post: 02-05-2010, 11:59 AM
  5. Add to customers/bookings form
    By Dega in forum Forms
    Replies: 1
    Last Post: 01-25-2010, 02:15 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