Results 1 to 4 of 4
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    Calculate date but set value to end of the year


    I am trying to calculate when the next test date is. It is 10 years from the last test but not until the end of whatever year it is in.

    So if the date is 5/1/02 then the next test is not due until 12/31/12. I have used this code

    Code:
    =DateSerial(Year([LastCoilTest])+10,Month([LastCoilTest]),Day([LastCoilTest]))
    to get the 10 years added but I am not sure how to get it to go to the end of that year.
    Thanks

  2. #2
    mrojas is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Location
    Concord California
    Posts
    72
    Store the results of your code above into a variable, say dteTheYear.
    Use the DatePart function to get the year, and then store into another a new variable, say dteEndOfYear the new date; "12/31/" & dteTheYear
    Use dteEndOfYear as needed

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Sorry I might need a little more help on this.

    Should i create this variable in a code module? I am not very good with VBA.
    would it be
    Private sub endyeardate()
    Dim strTestDate As String
    Dim strEndYear As String
    Dim newTestDate as Date
    Test Date =DateSerial(Year([LastCoilTest])+10,Month([LastCoilTest]),Day([LastCoilTest]))
    EndYear = DatePart ("yyyy", strTestDate)
    newTestDate = "12/31" & strTestDate

    End Sub

    Something like that. Sorry, kind of making it up based on what I know, or rather what I don't know. I would then have the form control to equal the value strTestDate.

  4. #4
    mrojas is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Location
    Concord California
    Posts
    72
    As to where to place this code, it depends how you're applying the "calculate" end of the year.

    Let's say you have a form with a button labeled "Calculate Next Test".

    Then, in the OnClick event of this button, insert the code as shown below:

    Private sub btnCalculate()
    Dim dteTestDate as date
    Dim str10Years as string
    dim dteEndof10Years as date

    dteTestDate=DateSerial(Year([LastCoilTest])+10,Month([LastCoilTest]),Day([LastCoilTest]))
    str10Years=DatePart ("yyyy", dteTestDate)
    dteEndof10Year= "12/31/" & str10Years
    End Sub

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

Similar Threads

  1. Query Help - calculate variance previous year
    By brtucker in forum Queries
    Replies: 1
    Last Post: 01-31-2013, 05:40 PM
  2. Replies: 4
    Last Post: 01-09-2013, 11:16 AM
  3. Replies: 4
    Last Post: 07-30-2012, 11:55 AM
  4. Replies: 4
    Last Post: 01-10-2012, 06:26 PM
  5. Replies: 11
    Last Post: 08-04-2010, 04:26 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