Results 1 to 8 of 8
  1. #1
    Bosworth is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    6

    Date calculation in textbox

    Access 2007, Windows 7

    On a form I have 2 textboxes, 1 for user input, the other a calculated date. The two values together represent a "Leave Year". The second textbox contains, [Firsttextbox]&" - "&([Firsttextbox]+364). Simple enough so far. The expected result from entering, for example, 2/10/2015, is 2/10/2015 - 2/9/2016, which is exactly what I need. But, using a hard figure like 364 will fail on 3/2/2015 when the extra day in Feb 2016 results in, 3/2/2015 - 2/29/2015. To compensate for this, I've added,

    "=IIf([Firsttextbox]>"2/28/2015",1,0)" to a third textbox and added it to the calculation as follows;

    [Firsttextbox]&" - "&([Firsttextbox]+364+[Thirdtextbox]) So far so good....almost.

    The "Leave Year" calculated is what I want, until 10/1/2015, when something goes awry. At 10/1/2015, the expression in the third text box evaluates to 0,and I lose my extra day.

    If the calculation is an Access 2007 problem/issue, will it evaluate correctly if it's migrated to a new version? And, if there's an easier way to get the result, please educate me.


    Another thing I need to do is similar, in that a date is entered and calculated to 7 days prior. If the calculated date falls on a Saturday, I need to have it adjust to Friday, the day before. Also, if another calculated date falls on Saturday or Sunday, I need to have it adjust to the following Monday. These are two separate calculated fields, but both are necessary. Any suggestions?



    Any help is appreciated.

    Bos
    Last edited by Bosworth; 02-17-2015 at 07:22 PM. Reason: Additional questions

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would try using DateAdd() to add a year and then subtract a day from that. DateAdd() should handle leap years correctly.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Bosworth is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    I would try using DateAdd() to add a year and then subtract a day from that. DateAdd() should handle leap years correctly.
    Paul, thanks for the suggestion here. This looks like the "right" way to do it. I tried applying it but I suspect it doesn't plug nicely into a textbox, rather belongs in a VBA event, which I'm not too savvy with. I'll have to do some research. Thanks again, very appreciated.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It should work either way. What did you try?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Bosworth is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    6
    Well, when you said "it should work either way", I took a closer look at it and found the right syntax....

    =DateAdd("yyyy",1,[Firsttextbox]) ..... where it used to be...... DateAdd("y",1,[Firsttextbox])

    Thank you Paul!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Bosworth is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    6
    Appreciated Paul. I hope I don't ask the same questions you've seen repeated ad nauseum. I know it can be exhausting but sometimes I need a little kick-start if I can't find the answer on my own. The last time I was really working with Access was back in Office XP, so the rust has really accumulated. I'll probably be the occasional visitor as I'm no longer using Access on a professional basis. Just a mere hobbyist now.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help! Don't worry, at this point it's hard to ask a question that hasn't been asked before in one form or another.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Some help with Date calculation
    By djclntn in forum Queries
    Replies: 14
    Last Post: 04-13-2013, 05:26 PM
  2. Date Calculation
    By logle0917 in forum Reports
    Replies: 3
    Last Post: 08-06-2012, 08:18 PM
  3. Date Calculation
    By Lazor78 in forum Forms
    Replies: 4
    Last Post: 01-25-2012, 11:53 AM
  4. Date Calculation
    By mrkaye in forum Forms
    Replies: 4
    Last Post: 11-10-2010, 10:42 AM
  5. Date Calculation ?
    By techexpressinc in forum Queries
    Replies: 2
    Last Post: 06-24-2009, 09:02 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