Results 1 to 8 of 8
  1. #1
    wcrimi is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    142

    Is it possible top do an Append or Update inside the same Query

    I have an existing process that looks at a table. If several conditions are met, it creates a new extract table with some of the information. About 10% of all the records meet all the criteria to become part of the extract.



    Sometimes, at a later date, I want to override those results.

    Here's the catch.

    Sometimes that means I have to override a field on an existing extract record (do an update) and sometimes that means I have to add record that didn't formerly quality but now does (append a new one). I don't necessarily know at the time of the override if the record is already on the extract file.

    If there a way to write a query where I give it the info it needs to look on the extract file, if it finds a match, just update the record and if it doesn't find the record add a new one?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    no, but you can run both an append & update queries 1 after the other.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I've heard it can be done, never tried it. See:

    https://thedbguy.blogspot.com/2016/0...th-append.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Yes it can definitely be done. Its sometimes called an UPSERT query though I prefer to call it an UPEND query.
    Its an APPEND query with an OUTER join
    See this link for more details and an example app http://www.mendipdatasystems.co.uk/u...ery/4594428616.

    It can be useful when synchronising data http://www.mendipdatasystems.co.uk/s...a-1/4594514001
    However, in my tests, I've found that its usually slightly slower than running each query separately
    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

  5. #5
    wcrimi is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    142
    The tricky part is that at the time I create my override table I don't know whether it's going to wind up being an update or an append.

    If I run the Update first, it will only update those records that matched on the key fields and more or less disregard the ones that need to be added.

    Then when I run my append, if the record doesn't exist it will add it, but if it does exist already (an update), it will just get a dupe trying to add the same key and error out.

    I guess I can live with that, but it's not ideal

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Quote Originally Posted by wcrimi View Post
    The tricky part is that at the time I create my override table I don't know whether it's going to wind up being an update or an append.

    If I run the Update first, it will only update those records that matched on the key fields and more or less disregard the ones that need to be added.

    Then when I run my append, if the record doesn't exist it will add it, but if it does exist already (an update), it will just get a dupe trying to add the same key and error out.

    I guess I can live with that, but it's not ideal
    There should be no issue whether you do this as two separate queries or as an 'upend' query
    Design the append part so it only appends new records not in the existing table.
    To do this you create an unmatched select query then change it to an append query

    The update part will only work on records that already exist

    If you look at my second link, you will see how I do this both as separate queries & then combined in order to synchronise data
    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

  7. #7
    wcrimi is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    142
    Quote Originally Posted by isladogs View Post
    There should be no issue whether you do this as two separate queries or as an 'upend' query
    Design the append part so it only appends new records not in the existing table.
    To do this you create an unmatched select query then change it to an append query

    The update part will only work on records that already exist

    If you look at my second link, you will see how I do this both as separate queries & then combined in order to synchronise data
    Thanks I'll see if I can figure that out this week. My Access knowledge is somewhat limited. I never did an umatched select query.

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You're welcome. Just follow the approach shown in the links.
    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

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

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2018, 11:39 PM
  2. Update/Append Query
    By joannakf in forum Queries
    Replies: 5
    Last Post: 05-21-2012, 04:02 PM
  3. Replies: 3
    Last Post: 03-11-2012, 03:35 PM
  4. Replies: 3
    Last Post: 12-20-2010, 09:22 AM
  5. Append/Update Query -- Need Help!
    By su-san in forum Queries
    Replies: 12
    Last Post: 11-08-2010, 12:52 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