Results 1 to 11 of 11
  1. #1
    mbiagiot is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2018
    Posts
    3

    Round Function in Update Query Returns Syntax Error

    Hi all, new member and first time post.



    I'm currently creating a process and I'm having the strangest issue that I can't seem to explain. Essentially what I'm trying to do is update values on a table to round based on specific criteria (Monthly vs Yearly).

    Here is the SQL code that works when I run this update query:

    Code:
    UPDATE TB_1201_SfaxCM 
       SET TB_1201_SfaxCM.MRR = IIf([TB_1201_SfaxCM].[Term]="Monthly",([TB_1201_SfaxCM].[DIDS]-1)*5+[TB_1201_SfaxCM].[Plan Value],([TB_1201_SfaxCM].[DIDS]-1)*4+[TB_1201_SfaxCM].[Plan Value]/12);

    However, I want yearly to round to 2 decimal places. I've tried this and keep getting a syntax error:

    Code:
    UPDATE TB_1201_SfaxCM 
       SET TB_1201_SfaxCM.MRR = IIf([TB_1201_SfaxCM].[Term]="Monthly",([TB_1201_SfaxCM].[DIDS]-1)*5+[TB_1201_SfaxCM].[Plan Value],([TB_1201_SfaxCM].[DIDS]-1)*4+ROUND([TB_1201_SfaxCM].[Plan Value]/12,2);

    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You don't have the closing parentheses for the Round() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,897
    Why save calculated value?

    Missing closing paren. Always make sure [], (), ", ' are in pairs (an even number total count).

    UPDATE TB_1201_SfaxCM
    SET TB_1201_SfaxCM.MRR = IIf([TB_1201_SfaxCM].[Term]="Monthly", ([TB_1201_SfaxCM].[DIDS]-1)*5+[TB_1201_SfaxCM].[Plan Value],([TB_1201_SfaxCM].[DIDS]-1)*4+ROUND([TB_1201_SfaxCM].[Plan Value]/12,2));
    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.

  4. #4
    mbiagiot is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2018
    Posts
    3
    Can't believe I missed that. However, I'm still somehow getting an error.

    I pasted in your code over the old one, and after trying to run the query i'm still getting: "Compile error. in query expression"

    Not sure what's going on

    Quote Originally Posted by June7 View Post
    Why save calculated value?

    Missing closing paren. Always make sure [], (), ", ' are in pairs (an even number total count).

    UPDATE TB_1201_SfaxCM
    SET TB_1201_SfaxCM.MRR = IIf([TB_1201_SfaxCM].[Term]="Monthly", ([TB_1201_SfaxCM].[DIDS]-1)*5+[TB_1201_SfaxCM].[Plan Value],([TB_1201_SfaxCM].[DIDS]-1)*4+ROUND([TB_1201_SfaxCM].[Plan Value]/12,2));

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,897
    What data type is MRR?

    I don't see anything else wrong with expression.

    Still wonder why you are saving a calculation that can be done when needed.

    Does the expression work in a SELECT query?
    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.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I think you need to move the Round to include the entire "false" side of the iif.

    UPDATE TB_1201_SfaxCM
    SET TB_1201_SfaxCM.MRR = IIf([TB_1201_SfaxCM].[Term] = "Monthly", ([TB_1201_SfaxCM].[DIDS] - 1) * 5 + [TB_1201_SfaxCM].[Plan Value], ROUND(([TB_1201_SfaxCM].[DIDS] - 1) * 4 + ([TB_1201_SfaxCM].[Plan Value] / 12), 2));

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,897
    Should be able ro round one term of calc. Works for me.
    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.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    June,

    My comment wasn't whether it would work, I was just trying to ensure the Yearly/false side was rounded to 2 digits.
    It may do the rounding even if the terms have different number of digits.. I'm not sure, but putting all terms within the round should ensure 2 digits.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,897
    Okay, agree but don't expect that will fix error although could be wrong.
    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.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Perhaps, OP could try this
    Code:
    UPDATE TB_1201_SfaxCM
    SET MRR = ROUND(IIf([Term] = "Monthly", ([DIDS] - 1) * 5 + [Plan Value], ([DIDS] - 1) * 4 + ([Plan Value] / 12)), 2);

  11. #11
    mbiagiot is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2018
    Posts
    3
    Hi All, I'll try this today at work and hopefully get the results I'm looking for so I can move on with creating this process. Such a pain!

    Thanks for the help here everyone

    Quote Originally Posted by orange View Post
    Perhaps, OP could try this
    Code:
    UPDATE TB_1201_SfaxCM
    SET MRR = ROUND(IIf([Term] = "Monthly", ([DIDS] - 1) * 5 + [Plan Value], ([DIDS] - 1) * 4 + ([Plan Value] / 12)), 2);

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

Similar Threads

  1. Replies: 3
    Last Post: 08-17-2018, 07:56 AM
  2. Syntax Error in UPDATE Query
    By lamore48 in forum Access
    Replies: 7
    Last Post: 02-19-2018, 12:04 PM
  3. Syntax error in UPDATE query
    By GraeagleBill in forum Programming
    Replies: 4
    Last Post: 02-14-2018, 12:38 PM
  4. Val function returns #error on text/percentage
    By allenjasonbrown@gmail.com in forum Queries
    Replies: 1
    Last Post: 06-23-2013, 08:24 AM
  5. Syntax Error 3144 in SQL Update Query.
    By Phred in forum Programming
    Replies: 4
    Last Post: 03-02-2012, 02:39 PM

Tags for this Thread

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