Help to calculate a time in the future

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neilj
    New Member
    • Feb 2007
    • 2

    Help to calculate a time in the future

    I would like to create a field that calculates a date that is 39 months from a date I am entering on a form. Once I fill in a date in a field, I would like to have Access calculate the next field which would be 39 months later. What formula would I enter to achieve that effect? Thank you!
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by neilj
    I would like to create a field that calculates a date that is 39 months from a date I am entering on a form. Once I fill in a date in a field, I would like to have Access calculate the next field which would be 39 months later. What formula would I enter to achieve that effect? Thank you!
    Assuming the Text Box containing your Date is txtDate, and the New Date will be contained in txtNewDate, then in the AfterUpdate() Event of txtDate type the following code:
    Code:
    Private Sub txtDate_AfterUpdate()
        If Not IsDate(Me![txtDate]) Then
           Exit Sub
        Else
           Me![txtNewDate] = DateAdd("m", 39, Me![txtDate])
        End If
    End Sub

    Comment

    • Michael R
      New Member
      • Nov 2006
      • 176

      #3
      You can also use this in your textbox Control Source:

      =DateAdd("m",39 ,[txtDate])

      Comment

      • neilj
        New Member
        • Feb 2007
        • 2

        #4
        Thanks for your Help!
        Originally posted by ADezii
        Assuming the Text Box containing your Date is txtDate, and the New Date will be contained in txtNewDate, then in the AfterUpdate() Event of txtDate type the following code:
        Code:
        Private Sub txtDate_AfterUpdate()
            If Not IsDate(Me![txtDate]) Then
               Exit Sub
            Else
               Me![txtNewDate] = DateAdd("m", 39, Me![txtDate])
            End If
        End Sub

        Comment

        • CSmith
          New Member
          • Feb 2007
          • 12

          #5
          Originally posted by neilj
          I would like to create a field that calculates a date that is 39 months from a date I am entering on a form. Once I fill in a date in a field, I would like to have Access calculate the next field which would be 39 months later. What formula would I enter to achieve that effect? Thank you!

          Use the dateadd(). In your query design view, click in the box where the field you want to calculate is and type
          =DateAdd("m",+3 9, [the field name for the date entered])
          once you click out of the box you will see
          Expr1:=DateAdd( "m",+39, [the field name for the date entered])
          Just change the word "Expr1:" to whatever you want the column name to be and there you go. Be sure there is a colon between your column name and the equal sign that starts the expression ... good luck

          Comment

          Working...