Results 1 to 2 of 2
  1. #1
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199

    Update with if condition

    I have a table

    Main

    Name Inter Intra Flag
    ------------------
    A BB CC
    as DD FF

    And Table

    Code table:

    code Flag
    ----------


    BB 1
    CC 0
    DD 0
    FF 0


    All the Flag reference taken from table, I want an update query where it checks if either of Inter and intra from Main table have flag as 1 from code table, it should update the flag in main as 1 else 0.

    Could this be possible?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Try:

    UPDATE Main SET Flag = IIf(IsNull(DLookup("Flag", "Code", "Flag=1 AND ([code]='" & [Inter] & "' OR [code]='" & [Intra] & "'"))), 0, 1)


    Actually, saving calculated data is usually a bad idea. The Flag value can just be calculated when need.

    SELECT [Name], Inter, Intra, IIf(IsNull(DLookup("Flag", "Code", "Flag=1 AND ([code]='" & [Inter] & "' OR [code]='" & [Intra] & "'"))), 0, 1) AS Flag FROM Main;
    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. Condition if there is a tempvar
    By Ruegen in forum Programming
    Replies: 1
    Last Post: 11-18-2013, 05:06 PM
  2. Help with using the AND condition
    By ssturges in forum Access
    Replies: 1
    Last Post: 11-25-2012, 12:36 AM
  3. condition in macros
    By frcastro in forum Programming
    Replies: 1
    Last Post: 06-23-2010, 03:16 AM
  4. Update 2 fields based on where condition.
    By Confused in forum Access
    Replies: 2
    Last Post: 11-19-2009, 05:21 PM
  5. How to use IIF condition
    By nshaikh in forum Queries
    Replies: 4
    Last Post: 09-12-2008, 01:23 AM

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