Results 1 to 2 of 2
  1. #1
    AlexTheGr8 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2019
    Location
    Ontario
    Posts
    11

    Default Value in Expression Builder

    Hi All,



    I'm working with an inherited database, and had a question on a change I was trying to make.

    There is a table in the database ("Payment Interface") that gets filled as we have new projects to pay. There needs to be a change where if one field (CostCentre) is one of two of the many options, then another field (PaymentArea) needs to change. So for example, if I'm paying out of cost centre 'example1' or 'example2' then the payment code that appears in the table should be '123', instead of the default of '890'.

    So I clicked on the field that needs to change, and where the last database designer put in the Default Value space "890", I clicked on the expression builder in default value, and tried to do an IIF statement. My thinking is that IF the criteria for the cost centre is met with either example1 or example2, then give me the value 123, and if not, keep it as the default for all other payments of 890.

    My expression looks like: =IIf([CostCentre]="example1" Or "example2",123,890)

    I'm getting an error that "the database engine does not recognize either the field 'CostCentre' in a validation expression, or the default value in the table "Payment Interface".

    What am I doing wrong? Any ideas are welcome.

    Thanks!
    Alex

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Firstly, NEVER do calculated fields at the Table level! This violates rules of normalization and is not compatible with any other database program!
    I do not know why Microsoft decided to allow this feature in newer versions of Access. It is a bad idea.
    On top of that, it is very limited in the kinds of calculations you can do.
    And I do not think you can do dependent calculations as default values in table anyway.

    In Access, all calculations should be done at the query level. Queries can be used for just about anything that Tables can, so there really is no reason to want to do them at the Table level instead of the Query level.
    The calculated field in your query would look like:
    Code:
    PaymentCode: IIf([CostCentre]="example1" Or [CostCentre]="example2",123,890)
    So note that "PaymentCode" would NOT be in your table. It is a calculatd field in your query.

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

Similar Threads

  1. Replies: 4
    Last Post: 05-03-2016, 01:51 PM
  2. expression builder
    By frustratedwithaccess in forum Access
    Replies: 7
    Last Post: 11-12-2014, 09:15 AM
  3. Expression Builder Help
    By Vibhor in forum Access
    Replies: 4
    Last Post: 12-11-2013, 11:42 AM
  4. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  5. expression builder
    By tonyl in forum Access
    Replies: 3
    Last Post: 11-26-2011, 12:00 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