Add Date Function (1 Viewer)

JPR

Registered User.
Local time
Yesterday, 17:50
Joined
Jan 23, 2009
Messages
192
I have created a form on which I have two textboxes with a Date format (mm/dd/yyyy)

Text1 will be used to store a specific date
Text2 should automatically add 1 month to the previous date

I have used the following code to the Default Value property of Text2 but after entering the date in TEXT1, TEXT2 does not update. Thank you for your help.

Code:
=DateAdd("m",1,[TEXT1])
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:50
Joined
May 7, 2009
Messages
19,246
add code to the Chage event of Text1:

Private Sub Text1_Change()
Me.Text2 = DateAdd("m", 1, [Text1])
End Sub
 

JPR

Registered User.
Local time
Yesterday, 17:50
Joined
Jan 23, 2009
Messages
192
Perfect. Thank you
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:50
Joined
Sep 21, 2011
Messages
14,366
Default Value only works for NEW records?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:50
Joined
Feb 19, 2002
Messages
43,371
Since the change event runs for every character you type, it is not appropriate for this purpose. Use the AfterUpdate event. BUT, better still, there is no need to store the calculated value at all. You can easily calculate it in any query you run. Storing calculated values violates normal forms.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:50
Joined
Feb 28, 2001
Messages
27,235
Default Value only works for NEW records?

Yep, only for new records for which a null would have been there had it not been for the default. Once there is a value in the slot, Access really has no interest in filling in something again and (by doing so) overriding an existing value.
 

Users who are viewing this thread

Top Bottom