Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    PTR is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    8

    Question Date Calculation

    Hi, I hope someone can help me. I am brand new to access and having difficulty with the following:


    I have a database with two fields, Date First Absent and Date Returned To Work. I would like to use a query to generate a report that shows the amount of days that the specific employee was absent from work. I am trying to use the DateDiff function to perform this calculation. The result of the calculation must be added to another field in the database called Days Absent. I have set the format of all three fields to Short Date. Any assistance or advice would be greatly appreciated.

    Thanks!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Where are you using the DateDiff() function and do you have it working. IMHO the best place for it would be in the forms query.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    PTR is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    8
    Hi Bob, thanks for your help. I am trying to build it into a query. I couldn't manage to get it working though. The error is Data Type Mismatch.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Can you show us the expression in which you are using DateDiff() or post a copy of the db with a few dummy records
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    PTR is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    8
    The expression that I am using is DateDiff([Date First Absent],[Date Returned To Work],"d")

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    Code:
    DateDiff("d",[Date First Absent],[Date Returned To Work])
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    PTR is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    8
    Thanks Bob, Your code works without any errors but the query is not supplying any results. I must be doing something wrong somewhere. I will shortly post the DB. Could you possibly have a look at it?

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by PTR View Post
    Thanks Bob, Your code works without any errors but the query is not supplying any results. I must be doing something wrong somewhere. I will shortly post the DB. Could you possibly have a look at it?
    Sure. No problem
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    PTR is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    8
    Can't get the DB to attach due to it being 996 Kb

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by PTR View Post
    Can't get the DB to attach due to it being 996 Kb
    Try Compact and Repair then create a zip file
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    I can't imagine why you couldn't post your original db. It is below with my proposed solution.
    You would be wise not to use spaces or special characters like / in the name of any object.
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  12. #12
    PTR is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    8
    Thanks Bob. I will rename that table without the /
    Thanks for your DB, I have extracted it and tried. When I run the query it doesn't provide any results.

    Am I missing something?

  13. #13
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    The solution is in the form called Absent / RTW.
    I have changed the forms Record Source property to a SELECT statement (this could be saved as a query which could then be named in this property) which includes a calculated field called DaysAbsent using the expression:
    Code:
    DaysAbsent: DateDiff("d",[Date First Absent],[Date Returned To Work])
    I created a new text box at the top of the forms detail section called DaysAbsent and set it's control soruce property to DaysAbsent.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  14. #14
    PTR is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    8
    Sorry Bob, I completely overlooked that. This is exactly what I wanted.
    Thanks for your help, I really appreciate it!

  15. #15
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by PTR View Post
    Sorry Bob, I completely overlooked that. This is exactly what I wanted.
    Thanks for your help, I really appreciate it!
    You're welcome.
    Be aware that the field called "Days Away" in your table is not needed.
    The calculated field used as the control source of the text box on the form is not and should not be saved to a table. Better to do the calculation whenever and wherever it is required.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 1
    Last Post: 02-10-2017, 03:10 PM
  2. Due Date Calculation
    By DFeil in forum Access
    Replies: 3
    Last Post: 10-29-2015, 10:55 AM
  3. Date Calculation
    By dharsh in forum Access
    Replies: 3
    Last Post: 06-26-2013, 11:19 AM
  4. Some help with Date calculation
    By djclntn in forum Queries
    Replies: 14
    Last Post: 04-13-2013, 05:26 PM
  5. Date Calculation -- HELP!
    By klaauser in forum Forms
    Replies: 0
    Last Post: 12-22-2008, 02:14 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