Results 1 to 5 of 5
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    494

    Adding fields in same update query with two if statements

    I have an if statement to update two field values:

    IIf([MaterialSign]="D",CCur([LaborCharge]/100),CCur([LaborCharge]/100)*-1)
    IIf([MaterialSign]="D",CCur([MaterialCharge]/100),CCur([MaterialCharge]/100)*-1)

    Also in the update query I have

    NetCharge
    Update to
    [LaborChargeNet]+[MaterialChargeNet]

    The if statments work fine, however the Net charge does not update. Is this because at the time of the query the value is not updated yet? Can I do this all in one query or will it take two queries?

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Are those two Iif expressions in the "Update To" line of the query, and if they are, what fields are they updating? If they are not in the "Update To", how are you using them?

    Where are the values for [LaborChargeNet] and [MaterialChargeNet] coming from?

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    494
    All three are in the update to section of the query
    I am afraid that the third one may not be able to calculate because it is dependent on the first two.
    I need the updated Labor and the Update Material to be able to get the Updated Net Charge. So I am wondering if there is some way to make it update Labor AND Material and then once those are done do the Net Charge update.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Instead of referring to the first two calculated fields by their alias ([LaborChargeNet] and [MaterialChargeNet]), just use the original expressions again, so net charge will update to:

    IIf([MaterialSign]="D",CCur([LaborCharge]/100),CCur([LaborCharge]/100)*-1) + IIf([MaterialSign]="D",CCur([MaterialCharge]/100),CCur([MaterialCharge]/100)*-1)

  5. #5
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    494
    I see, that is clever. I should have thought of that. Since it is not updating then then it will still use the earlier values. I have tested it and it works. Thanks, that saves me an extra query in my subroutine.

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

Similar Threads

  1. Update query with multiple part if statements
    By Darkmatter5 in forum Access
    Replies: 3
    Last Post: 08-14-2014, 12:26 PM
  2. Replies: 14
    Last Post: 05-07-2014, 05:11 PM
  3. Update query adding
    By xtrareal22 in forum Queries
    Replies: 1
    Last Post: 12-10-2013, 06:34 AM
  4. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  5. IIF Statements and Update Queries.
    By nicknicknick in forum Queries
    Replies: 1
    Last Post: 06-05-2011, 12:08 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