Dates in text boxes

Z

Zoe

I am designing a form that will have 3 text boxes for dates.

The first text box (named cdate) will be filled in by the user in response
to a question like "What is the date of conversion?"

The two additional text boxes should be filled in automatically based on the
entry in cdate.

Text box edate should display the day before cdate.
Example: If cdate = 09/16/08 then edate should = 09/15/08

Text box bdate should display the date that is 2 years prior to cdate.
Example: If cdate = 09/16/08 then bdate should = 09/16/06

I woulld like the user to be able to modify both bdate and edate but bdate
cannot be more than 2 years before cdate.

Can this be accomplished?
Thanks in advance,
Zoe
 
J

John W. Vinson

I am designing a form that will have 3 text boxes for dates.

The first text box (named cdate) will be filled in by the user in response
to a question like "What is the date of conversion?"

The two additional text boxes should be filled in automatically based on the
entry in cdate.

Text box edate should display the day before cdate.
Example: If cdate = 09/16/08 then edate should = 09/15/08

Text box bdate should display the date that is 2 years prior to cdate.
Example: If cdate = 09/16/08 then bdate should = 09/16/06

I woulld like the user to be able to modify both bdate and edate but bdate
cannot be more than 2 years before cdate.

Can this be accomplished?

You can use some VBA code (or in A2007, you may want to use a Macro) in the
AfterUpdate event of cdate. For example,

Private Sub cdate_AfterUpdate()
If IsDate(Me!cdate) Then
Me!edate = DateAdd("d", -1, Me!cdate)
Me!bdate = DateAdd("yyyy", -2, Me!cdate)
Else
MsgBox "Please enter a valid date in cdate", vbokonly
End If
End sub


You'll need to use code in the BeforeUpdate event of bdate to limit the range.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top