Results 1 to 5 of 5
  1. #1
    Piyushjais is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jan 2018
    Posts
    2

    Error in Access (#Type!)

    I have inserted this argument in a calculated field



    "IIf([From Date]-[Submission Date]>=0,[Total Days]-2,IIf([From Date]-[Submission Date]>=1,[Total Days]-1,IIf([From Date]-[Submission Date]>=2,[Total Days],0))) & [Mess Card]=Yes"

    I am getting an error "#Type!". I am not an expert on access so require some help on the above. Is the argument wrong? what could be a correct argument. Basically i am checking the no of days leave has been applied. The calculation is based on a 48 hrs notice after which the leave is counted and also the mess card has to be deposited. If not deposited then the leaves are not accounted.

    Please help

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Are your date fields all date/time type and not text?

    You should reverse the conditions. Test >=2 first then >=1 then >=0

    Why are you concatenating the result of [Mess Card]=Yes? This calc will return either -1 or 0.

    Advise not to use spaces nor punctuation/special characters (underscore only exception) in naming convention.
    Last edited by June7; 01-17-2018 at 03:00 PM.
    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
    Piyushjais is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jan 2018
    Posts
    2
    The entire calculation is based on the condition whether the card has been submitted or not. Is there any other way of checking?

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Create a form based on the table using the wizard (or query if more than one table involved), add all the fields mentioned in the expression you have above. Then take each calculation and make it its own field (e.g. one field will have =[From Date] - [Submission Date]).

    Once you have each part of the calc working, you can begin to put them together, adding one piece at a time.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I've done the following:
    a) created an IIf section for [Mess Card]=True and which is then broken down into your 3 IIf statements
    b) reversed the 3 statements so you have >=2 ; 1; 0 as your conditions
    c) added Null as the output if [Mess Card]=False

    I've assumed 'Mess Card' is a Yes/No field
    If its text, replace True with 'Yes'

    Code:
    IIf([Mess Card]=True,IIf([From Date]-[Submission Date]>=2,[Total Days],0,IIf([From Date]-[Submission Date]=1,[Total Days]-1,IIf([From Date]-[Submission Date]=0,[Total Days]-2,0))),Null)
    Hopefully I've got the bracketing correct but no promises ...
    TEST it carefully & CHECK it gives correct answers
    However, personally I wouldn't do an expression with 4 IIf as its too easy to make mistakes

    A much easier approach would be a UDF with select cases for >=2;1;0 scenarios ... or a lookup table
    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

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

Similar Threads

  1. Replies: 5
    Last Post: 10-28-2016, 08:03 AM
  2. Replies: 2
    Last Post: 03-13-2015, 05:49 AM
  3. Replies: 5
    Last Post: 09-18-2014, 12:26 PM
  4. Replies: 2
    Last Post: 08-06-2012, 08:27 AM
  5. Type mismatch Error after upgrading to Access 2010
    By twm07073 in forum Programming
    Replies: 7
    Last Post: 06-13-2012, 10:07 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