Syntax for previous year with DateSerial

S

Susan L

To create a report for December of the previous year, I need to reset a
"Start Date" on a form to the previous January for a cumulative report. I've
been able to change other code using Year(Date))-1, but am stumped on this
one, because for all months other than December, my current code works.

Here's what I've tried that does not work: There's a syntax error on the
first line, but I'm not sure about the second.

If(DateSerial(Year(Date()), 1, 1) Then
[Forms]![frm_Export_Metrics]![StartDate] = DateSerial(Year(Date) -
1, 12, 1)
'Resets Start Date on Export Metrics form to 1/1/yyyy
Else: [Forms]![frm_Export_Metrics]![StartDate] =
DateSerial(Year(Date), 1, 1)
End If
Any suggestions?
 
D

Douglas J. Steele

DateSerial(Year(Date()), 1, 1) will always be true, so I don't understand
what your If statement is supposed to do.

How can you tell that it's a report for December of the previous year?
 
S

Susan L

Here is the logic of what I want:
If the date is January (of any year), reset [StartDate] on the form to
January 1 of the previous year.
Otherwise, reset [StartDate] to January 1 of the current year.

We always run reports on the fifth business day following the month being
reported, so January's report will be run in February.

I hope this clarifies.
--
susan


Douglas J. Steele said:
DateSerial(Year(Date()), 1, 1) will always be true, so I don't understand
what your If statement is supposed to do.

How can you tell that it's a report for December of the previous year?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Susan L said:
To create a report for December of the previous year, I need to reset a
"Start Date" on a form to the previous January for a cumulative report.
I've
been able to change other code using Year(Date))-1, but am stumped on this
one, because for all months other than December, my current code works.

Here's what I've tried that does not work: There's a syntax error on the
first line, but I'm not sure about the second.

If(DateSerial(Year(Date()), 1, 1) Then
[Forms]![frm_Export_Metrics]![StartDate] = DateSerial(Year(Date) -
1, 12, 1)
'Resets Start Date on Export Metrics form to 1/1/yyyy
Else: [Forms]![frm_Export_Metrics]![StartDate] =
DateSerial(Year(Date), 1, 1)
End If
Any suggestions?
 
D

Douglas J. Steele

If Month(Date()) = 1 Then
[Forms]![frm_Export_Metrics]![StartDate] = _
DateSerial(Year(Date) - 1, 1, 1)
Else
[Forms]![frm_Export_Metrics]![StartDate] = _
DateSerial(Year(Date), 1, 1)
End If

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Susan L said:
Here is the logic of what I want:
If the date is January (of any year), reset [StartDate] on the form to
January 1 of the previous year.
Otherwise, reset [StartDate] to January 1 of the current year.

We always run reports on the fifth business day following the month being
reported, so January's report will be run in February.

I hope this clarifies.
--
susan


Douglas J. Steele said:
DateSerial(Year(Date()), 1, 1) will always be true, so I don't understand
what your If statement is supposed to do.

How can you tell that it's a report for December of the previous year?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Susan L said:
To create a report for December of the previous year, I need to reset a
"Start Date" on a form to the previous January for a cumulative report.
I've
been able to change other code using Year(Date))-1, but am stumped on
this
one, because for all months other than December, my current code works.

Here's what I've tried that does not work: There's a syntax error on
the
first line, but I'm not sure about the second.

If(DateSerial(Year(Date()), 1, 1) Then
[Forms]![frm_Export_Metrics]![StartDate] =
DateSerial(Year(Date) -
1, 12, 1)
'Resets Start Date on Export Metrics form to 1/1/yyyy
Else: [Forms]![frm_Export_Metrics]![StartDate] =
DateSerial(Year(Date), 1, 1)
End If
Any suggestions?
 

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