Results 1 to 3 of 3
  1. #1
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16

    Question UPDATE with count

    Hi there,

    Please see the tables below....

    Master
    Organisation (No Duplicates) Office
    1 a
    2
    3
    4 a
    5



    Update
    Organisation Office
    1 a
    1 b
    1 c
    2 a
    3 a
    3 b
    4 a
    5 a
    5 b

    I want to write an UPDATE query to update the 'Master' table's 'Office' column with an office from the 'Update' table where:
    • Master!Office = blank
    • Count(Update!Organisation)=1



    This is what the result should look like:

    Master Result
    Organisation (No Duplicates) Office
    1 a
    2 a
    3
    4 a
    5


    Please advise!

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Here's one method which uses 3 queries
    a) Aggregate query to identify those organisations with one record only
    b) Make table query - to save the values of those for the update query.
    Needed as you can't run your update query based on an aggregate query
    c) Update query - to update master table form table created in b)

    See attached for full solution.

    Note - I hope this is just example data as you shouldn't use Update as a table name & all tables should have a PK field
    Attached Files Attached Files
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Or instead of saving data to an intermediate table, VBA loops through recordset.

    But why save aggregate data anyway? Calculate when needed.
    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.

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

Similar Threads

  1. Replies: 13
    Last Post: 03-22-2018, 09:28 PM
  2. Replies: 6
    Last Post: 06-26-2017, 07:42 PM
  3. Replies: 2
    Last Post: 06-30-2016, 06:38 PM
  4. Replies: 8
    Last Post: 10-03-2013, 08:11 AM
  5. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 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