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

    Select An Update Query Based on Condition

    Hi there,



    I want to write an update query to do the following...

    ---

    If (Condition A) = TRUE
    Perform update no. 1.......

    Else If (Condition B) = TRUE
    Perform update no. 2.......

    Else If (Condition C) = TRUE
    Perform update no. 3.......

    Else (Condition D) = TRUE
    Perform update no. 4.......

    ---

    How can I achieve this in SQL?


    Many thanks!

  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
    You've already written the basic structure
    You just need to create update queries or SQL statements as preferred
    e.g.

    Code:
    If ConditionA = TRUE
    CurrentDB.Execute "UPDATE TableName SET TableName.FieldName = some value" & _        " WHERE optional filter criteria;"
    
    Else If ConditionB = TRUE
    DoCmd.OpenQuery "qryUpdateQueryName2"
    
    etc
    Or you can use Select Case statements instead of If...ElseIf...End If which is usually easier to read and sometimes faster
    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
    djmixer135 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    16
    Thanks for your response.

    Is there any way to achieve this without uson VBA?

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You could possibly use a macro but I never use them so can't advise.
    However, the vba needed is fairly simple
    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
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904

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

Similar Threads

  1. Lookup Field in Query based on condition
    By jkk17 in forum Queries
    Replies: 2
    Last Post: 04-02-2015, 06:58 AM
  2. Marco Condition based off a Query
    By bigbox486 in forum Macros
    Replies: 1
    Last Post: 03-30-2015, 09:02 AM
  3. Select query with condition date later or equl to
    By robs23 in forum Programming
    Replies: 8
    Last Post: 12-20-2014, 02:02 PM
  4. Add Query Based on if Condition
    By shakeelmscw in forum Queries
    Replies: 17
    Last Post: 01-18-2013, 02:35 AM
  5. Update 2 fields based on where condition.
    By Confused in forum Access
    Replies: 2
    Last Post: 11-19-2009, 05:21 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