Results 1 to 7 of 7
  1. #1
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100

    Create a Calculation to Produce Text


    Hi Guys, just trying to create a calculation in a table field called BCAD which isn't working. I'm trying to calculate:

    iif(period < 0, "BC", iif( period >0, "AD", ""). Just wondering if someone can point out my error. Screenshot below. thanks.

    Click image for larger version. 

Name:	Access Calc..jpg 
Views:	13 
Size:	19.3 KB 
ID:	35080

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    What is the error message?

    You are missing a closing paren in that expression. Parens and brackets as well as quote marks and apostrophes must always be in pairs.

    But why use the second IIf()? Will 0 ever be a value in the field?

    IIf([period] < 0, "BC", "AD")
    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.

  3. #3
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Hi June,

    Problem solved. I was attempting to build the expression in my main table in Design View. In fact, I can only build expressions in either Forms, Queries and Reports. So I opened the control source of BCAD in Properties and built the expression as follows:

    iif([txtPeriod] <0,"BC",iif({txt.period] >0,"AD",""))

    Works perfectly. Cheers.
    Attached Thumbnails Attached Thumbnails Access Calc.2.jpg  

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    you could also just use the format property

    "AD";"BC";"":""

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Quote Originally Posted by Ajax View Post
    you could also just use the format property

    "AD";"BC";"":""
    Just to expand upon Ajax's suggestion, the 4 format conditions correspond to positive; negative; zero; null values
    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

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    just a thought - there wasn't a year 0 so formula just needs to be

    iif([txtPeriod] <0,"BC","AD")

    or formatting

    "AD";"BC";"AD"

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    Certainly can do calcs in table with Calculated type field. Apparently, BCAD already had data and therefore could not convert to calculated field. Could have deleted and recreated the field as calculated type. Most experienced developers would recommend not using calculated field in table, however, your expression should work. It does 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.

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

Similar Threads

  1. Replies: 14
    Last Post: 12-28-2015, 07:51 AM
  2. Replies: 2
    Last Post: 03-10-2015, 11:47 AM
  3. Replies: 10
    Last Post: 03-05-2015, 07:33 PM
  4. Help with Text calculation
    By yagerlegi in forum Forms
    Replies: 4
    Last Post: 12-04-2014, 08:54 PM
  5. Replies: 12
    Last Post: 11-13-2014, 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