DateAdd question

  • Thread starter Thread starter Junior
  • Start date Start date
J

Junior

Trying to set expiration date field 60 days forward from today
The code below works and sets Exp.dte one year ahead
How can i change it to set Exp.Dte 60 days ahead?
thanks

strSQL = "UPDATE tblDate SET tblDate.InstDte = " & strCurrentdate & ",
tblDate.LastUsed = " & strCurrentdate & ", " & _
"tblDate.ExpDte = #" & Format(DateAdd("yyyy", 1, Date),
"mm/dd/yyyy") & "#"
dbs.Execute strSQL
 
Trying to set expiration date field 60 days forward from today
The code below works and sets Exp.dte one year ahead
How can i change it to set Exp.Dte 60 days ahead?
thanks

strSQL = "UPDATE tblDate SET tblDate.InstDte = " & strCurrentdate & ",
tblDate.LastUsed = " & strCurrentdate & ", " & _
"tblDate.ExpDte = #" & Format(DateAdd("yyyy", 1, Date),
"mm/dd/yyyy") & "#"
dbs.Execute strSQL

This information is readily available in your computer.
You should look up the DateAdd function in VBA help before posting.
That's what it's for!!!

The function has arguments which you are supposed to set so that it
knows whether you wish to add days, months, or years.

Anyway, to set a date 60 days from today, all you need is a simple
tblDate.ExpDate = Date + 60

If you want to use DateAdd, then
tblDate.ExpDte = DateAdd("d",60,Date)

Date is a Date/Time value. .
If you are putting the above date value into a Date Datatype field,
there is no need to add the "#" or to format it.

Also, why do you need to have to store the expiration date in your
table at all.
Storing calculated data is wasteful of memory, and can lead to storing
incorrect data if the underlying data has been changed.
As long as you have the Date stored, all you need do is calculate the
ExpDate when you need that information, using either expression above.

Assuming the date of sale (or whatever) was stored in a field named
[SaleDate], use:
Expiration = [SaleDate] + 60
 
Back
Top