How do you calculate a date on a form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Barry Putt
    New Member
    • Jul 2010
    • 2

    #1

    How do you calculate a date on a form?

    Hello,

    I've designed a form where I'd like users to be able to enter a date into field number one. When they do that, field number two will be populated with a date that is 27 years from the date they entered. How do I go about setting this up?

    Will the data in field number two be saved to the corresponding field the table the form is associated with?

    Thanks.
    Barry
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Answering the second question first, absolutely not! Most calculated values, and certainly this one, should not be stored in the underlying table but rather simply re-calculated when needed, such as in another form or report. So, with Field2 being Unbound:
    Code:
    Private Sub Field1_AfterUpdate()
     Me.Field2 = DateAdd("yyyy", 27, Me.Field1)
    End Sub
    
    Private Sub Form_Current()
     Me.Field2 = DateAdd("yyyy", 27, Me.Field1)
    End Sub
    Linq ;0)>

    Comment

    Working...