Results 1 to 10 of 10
  1. #1
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232

    calcuating field in a query


    I have two field in a query that I would like to calculate
    Field Name : “Time” and “Hours”
    I would like to calculate the field Time*14 if the hoursfield is empty if no time in the time field the default would be “0”
    I tried this but it still calculated if there was hours inhours field.
    BY HOURS WORKED: IIf([Hours]="IS Null",Nz([Time]*14),0)

    Thanks Angie


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You only need the NZ, not the IIF.
    =nz([hrs]*14)

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Try removing the quotes. "Is Null" would be a text value and not a test for Null.
    You should not be using reserved words for field or object names (Time). For a moment, I thought Hours was reserved also, but it is Hour.
    http://allenbrowne.com/AppIssueBadWord.html#H
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    ok I got this to work
    BY HOURS WORKED: IIf([Hours] Is Null,Nz([Time]*14))

    The only thing I can not get it to do is if there is nothing in the "TIME" field is shows #error.
    I need it to default to nothing iF there is nothing in the TIME field

    Thanks Again Angie

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    you dropped the necessary parameter that tells the function what to use if the value is null
    IIf([Hours]=IS Null, Nz([Time]*14),0)

  6. #6
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    I need it to default to "0" if the fields [hours] and [time] is empty.
    it still show the #error for the entry with the hours and time is empty everthing else works

    Thanks

  7. #7
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I think Micron made a typo in he response.
    I don't think there should be ab equal sign before the words IS Null.
    Code:
    IIf([Hours] Is Null, Nz([Time]*14),0)

  8. #8
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Correct. I copied from a previous post without scrutinizing. Thanks.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I copied from a previous post without scrutinizing.
    Funny, I did the same think last week, and it tripped me up too!

  10. #10
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Thanks Everyone I have it working

    Angie
    Last edited by angie; 12-19-2016 at 04:33 PM.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-31-2015, 10:38 PM
  2. Replies: 3
    Last Post: 07-09-2014, 06:39 AM
  3. Replies: 3
    Last Post: 03-26-2014, 10:49 AM
  4. Calcuating Values
    By WhatnThe in forum Access
    Replies: 22
    Last Post: 02-03-2010, 05:26 AM
  5. Calcuating Values Pt/2
    By WhatnThe in forum Access
    Replies: 3
    Last Post: 01-02-2010, 02:14 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