Date Calc Question

  • Thread starter Thread starter jbc
  • Start date Start date
J

jbc

Hello,

I would like Access to perform a calculation. I have:

checkbox called chkIsRenewal
textbox called intYears
textbox called txtExpirationDate

When chkIsRenewal is checked I would like the intYears to
be added to txtExpirationDate.

I would also like the formula to make sure that the
expiration date is the LAST day of the month.

This would save a lot of problems, especially during leap
year when I can't remember how many days are in a month!

Thanks.

jbc
 
I got it to work by using:

If IsDate(Me.txtExpirationDate2) Then

Me.txtExpirationDate2 = DateSerial(Year
(Me.txtExpirationDate2) + intYears, Month
(Me.txtExpirationDate2) + 1, 0)

End If

jbc
 
-----Original Message-----
Hello,

I would like Access to perform a calculation. I have:

checkbox called chkIsRenewal
textbox called intYears
textbox called txtExpirationDate

When chkIsRenewal is checked I would like the intYears to
be added to txtExpirationDate.

I would also like the formula to make sure that the
expiration date is the LAST day of the month.

This would save a lot of problems, especially during leap
year when I can't remember how many days are in a month!

Thanks.

jbc
.

Add the following code to the After Update event of
chkIsRenewal:
Dim currdate As Date
Dim int1 as integer
int1 = me.intYears
currdate = DateAdd("YYYY", int1, txtExpirationDate)
currdate = DateSerial(Year(currdate), Month(currdate) + 1,
0)
txtExpirationDate = currdate

You might want to do an If Then Else statement to check
the value of the checkbox and only run the code if the box
is in fact checked.
 
Back
Top