Results 1 to 13 of 13
  1. #1
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88

    Display only digits on left of decimal maximum three digits in Age Calculation


    Ok I refine this statement a little I am using it as control source in a form. I still need some help tweaking it. Any Ideas!!

    =IIf(IsNull([DOB])=False,Date()-[DOB],Null)/365.25

    However, I only want it to display the age with out everything after decimal point.
    For example, if I entered 06/26/1936 as DOB on form the answer I get is 82.78165639972621492128678987.

    How would I round it to show just the 82 in answer? I want to be able to display up to three digits for those over 100 years old.

    Thanks everyone for their individual input and taking the time to help me I do appreciate it.

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    =IIf(IsNull([DOB])=False,Date()-[DOB],Null)/365.25
    This means that IF there is a DOB value, return Date()-[DOB] otherwise return Null / 365
    You cannot do math on Null, nor can you compare it to anything (e.g. = Null)

    I think you want
    =IIf(IsNull([DOB]),put value if nulll here, expression if not null here)

    EDIT - forgot the main question
    I doubt you've run into a record where the field is null otherwise you should have generated an error.
    You can use Format function to trim decimals, or you can use a conversion function if you don't want any decimals at all (e.g. CLng)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88
    I tried =IIf(IsNull([DOB]),put value if null here, expression if not null here) I am not sure what values you want me to put there. Can you give me example please

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I have no idea what you want where there is a null value. The field involved seems to be numeric because you're doing calculations, so maybe

    =IIf(IsNull([DOB]),0, (Date - [DOB])/365.25)

    or to show no decimals (does not remove them from the actual value, just hides them)
    =IIf(IsNull([DOB]),0, Format((Date - [DOB])/365.25)
    ,0)

    or to actually remove them
    =IIf(IsNull([DOB]),0, CLng((Date - [DOB])/365.25))

    If 0 is not appropriate, pick something else. You could even use null if your table field design allows it.
    =IIf(IsNull([DOB]),Null, (Date - [DOB])/365.25)

    I don't think you need the () after Date

  5. #5
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Try breaking your code down into something simple.

    e.g IIF([DOB], A )

    This should return A if DOB has a value. No need to get involved with NULL. NULL is unique and is not equal to anything. There is nothing much you can do with it.

    If DOB returns a value then do your calculation. If not then do nothing.

    I hope I am correct as this has not been tested.

    Please come back after trying this and you need more help.

  6. #6
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    =IIf(IsNull([DOB]),0, (Date - [DOB])/365.25)

    This will divide DOB by 365.25 before it is taken away from DATE.

    Not sure if this is what you want.

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Quote Originally Posted by Rainlover View Post
    =IIf(IsNull([DOB]),0, (Date - [DOB])/365.25)

    This will divide DOB by 365.25 before it is taken away from DATE.

    Not sure if this is what you want.
    I think you missed a parenthesis?
    (Date - [DOB]) /365

  8. #8
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Quote Originally Posted by Micron View Post
    I think you missed a parenthesis?
    (Date - [DOB]) /365
    You are right.

    Thanks for that.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  10. #10
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88
    I want to thank everyone who helped me fix my Age Calculation issue in my access form. I thought I would post exactly the steps I did maybe to help someone else with similar issues. Once again thanks everyone!!
    This code works perfect to calculate age when used in a form.
    Steps:
    (1) Create a form
    (2) Under View Select Design View
    (3) Add a new Text Box
    (4) Select Property Sheet Tab on Access top Ribbon
    (5) Double Click on Text Box Label Name It Age (You may name it whatever you want)
    (6) Than Select unbound box of text box
    (7) On Property Sheet selections on right select Data tab
    (8) In Control Source select … (three dots on right of Control Source)
    (9) In Expression Builder that appears enter the following code
    =IIf(IsNull([DOB])=False,Int((Date()-[DOB])/365.25),Null)

    **Note: the DOB refers to form source that contains the Date of birth
    ***Remember you don't need to save Age in a Table because it continuously changes and updates.

    (10) Hit OK Close Box
    (11) Switch back to Form View and Age should appear in the text box you created


  11. #11
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    wes

    Sorry to be the bearer of bad news but your code is wrong. There are not 365/4 days to a year. February changes.

    Test it for 4 years on the 1st Day of March. then the 28th and 29th of February.

    This should highlight the error.

    I do apologise for not reading your Title correctly. Had I had realised you were calculating age I would have been of better help.

    I will send you a working copy for age a little later. I have something to do just now.

  12. #12
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Age.mdb

    Try This

    Open the form to the full size.

    You need to test it because I did not.

  13. #13
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    I assume you are happy with what you have and are not going to look at what I posted.

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

Similar Threads

  1. Too many digits after decimal point!
    By euphonium01 in forum Queries
    Replies: 3
    Last Post: 02-18-2016, 05:54 AM
  2. Calculation - formation of digits
    By stephenchan433 in forum Access
    Replies: 3
    Last Post: 01-16-2016, 08:49 PM
  3. Replies: 7
    Last Post: 12-23-2015, 01:02 PM
  4. Too many digits!
    By Degs29 in forum Access
    Replies: 1
    Last Post: 05-30-2013, 12:53 PM
  5. Left function with various lenth of digits
    By mohsin74 in forum Queries
    Replies: 0
    Last Post: 07-10-2007, 02:00 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