Results 1 to 5 of 5
  1. #1
    dredgy is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Australia
    Posts
    2

    Default value is result of IF() statement.

    Hi, I'm interpreting an Excel spreadsheet into an Access database, and I have one particular problem.

    In one column in excel, the formula used, uses nested if statements and the weekday() function and I'm not sure how to conver the Excel syntax to Access.

    I always want the default value of this field to be:




    Code:
    =IF(WEEKDAY(Sheet1!$A7) = 7, $B$2, IF(WEEKDAY(Sheet1!$A7) = 1, $B$3, $B$1))
    Or, in slightly more database relatable terms:

    Code:
    =IF(WEEKDAY([@date_column]) = 7, [!another_table@another_column2], IF(WEEKDAY([@date_column]) = 1,[!another_table@another_column], [!another_table@another_column]))
    Hard to explain, and I'm sure less than ideal syntax.

    So the table has two columns, "date_column" and "weekday_column". So the default value of "weekday_column" checks "date_column" for the day, and then returns the appropriate value from "another_table". If it's Saturday, you get one value, if Sunday another, any other day of the week you get the standard.

    Thank you very much for any help, and hit me up with any questions, I know it's terribly explained.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    It is a bit confusing. Perhaps posting example of the different scenarios would help.

    Note, if you have one field that is dependent or is calculated based on another field, that second field should NOT be stored at the table level, but rather calculated in a query.
    If you have a complex calculation, I would recommend creating a User Defined Function (UDF) to do it.

  3. #3
    dredgy is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Australia
    Posts
    2
    Hi thanks for your answer. Definitely not storing it at the table level (now) but instead doing a form and trying to calculate it from there.

    At this stage I haven't quite gotten to where I want to be so don't need help (think I'm understanding it alright so far). It was just transitioning from a spreadsheet way of thinking to a database way of thinking.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Don't try to do the calculations directly on the Form. It is easier/better to do them in a query.
    You can then use the query as the Source of your Form, and list those calculated values there that way.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    The Access equivalent would be IIf()

    Something like:

    =IIf(WEEKDAY([fieldname]) = 7, value2, IIf(WEEKDAY([fieldname]) = 1, value3, value1))

    or

    =IIf(WEEKDAY([fieldnameA]) = 7, [fieldnameB2], IIf(WEEKDAY([fieldnameA]) = 1, [fieldnameB3], [fieldnameB1))
    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. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. Replies: 7
    Last Post: 01-11-2012, 12:24 PM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. result -1 in Iff statement
    By newtoAccess in forum Queries
    Replies: 10
    Last Post: 04-08-2011, 05:43 PM
  5. default value IIf statement
    By jmk909er in forum Forms
    Replies: 0
    Last Post: 10-22-2010, 07:06 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