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.
 
L

Linq Adams via AccessMonster.com

As John said, to limit the date in cDate, if manually changed:

Private Sub cDate_AfterUpdate()
Me.eDate = DateAdd("d", -1, Me.cDate)
Me.bDate = DateAdd("yyyy", -2, Me.cDate)
End Sub
 
L

Linq Adams via AccessMonster.com

Blast! Copied and pasted the wrong part! Should have been to limit bDate:

Private Sub bDate_BeforeUpdate(Cancel As Integer)
If bDate < DateAdd("yyyy", -2, Me.cDate) Then
MsgBox "bDate Cannot Be More Than 2 years Prior to cDate!"
Cancel = True
End If
End Sub
 

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