Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I did stress that you would have problems with this code back in post #8:

    You need to replace the DOB & Date fields with those in your database. Possibly this:

    Service to date = DateDiff("yyyy", [Reg],[Left]) + (Format([Reg], "mmdd") > Format([Left], "mmdd")) _
    + DateDiff("yyyy", [Returned], [Left2]) + (Format([Returned], "mmdd") > Format([Left2], "mmdd")) _
    + DateDiff("yyyy", [Returned2], Date()) + (Format([Returned2], "mmdd") > Format(Date(), "mmdd"))

    NOTE: I've just used the field names from your original incorrect expression.
    You used Date() in your expression so I have as well. Perhaps that should be RetirementDate instead.

    The above doesn't need Int as each part of the expression is an integer

    However, what if someone leaves and returns 3 or more times before retiring. Your field structure can't handle that


    That's why it needs to be normalised.

    Also you may get errors if someone has no [Left] data (another bad choice of field name) or Returned, Left2, Returned2 data
    So you may need to tweak it further
    The problem is that you are trying to use an Excel like data structure and Access is not designed to work like a spreadsheet

    You really need to learn about normalising data in Access or do this in Excel

    You can get a little further by wrapping each date field in the Nz function but it will rapidly get very messy
    If you must persist with this data structure, I would suggest you create a user defined function for the purpose.

    Also remember that the expression as supplied will not give any part years served.
    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

  2. #17
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    From Post #1
    Quote Originally Posted by neil12sc View Post
    ....Teachers are allowed to leave the school for taking of examinations, wedding etc. Left and Left2 are for leaving dates.......
    You should be aware that "Left" is a reserved word and a built in function in Access and shouldn't be used for object names.

    I agree with Colin and think you should write a UDF because of the complexity of the calculation.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-24-2019, 02:35 PM
  2. Replies: 5
    Last Post: 09-29-2015, 12:40 PM
  3. Replies: 3
    Last Post: 09-22-2014, 04:38 PM
  4. Calculate number of years.
    By sha1023012 in forum Access
    Replies: 4
    Last Post: 10-02-2012, 08:33 AM
  5. Replies: 1
    Last Post: 11-12-2010, 01:16 AM

Tags for this Thread

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