Dates

Q

quixote

I have created a report and ran into a problem when the
year changed. In the report I must show Previous month as
a field and Year as a field. I want to run this report on
the first day of every month for the previous month. My
problem is...how in January do I make sure that I get data
for December of the previous year. This "DatePart
("yyyy",Now())" won't work in Jan.
Thanks
 
L

losmac

yourDate = DateSerial(Year(Date), Month(Date), 1 - 1)

This code gives You last day of previous month.
 
M

Marshall Barton

quixote said:
I have created a report and ran into a problem when the
year changed. In the report I must show Previous month as
a field and Year as a field. I want to run this report on
the first day of every month for the previous month. My
problem is...how in January do I make sure that I get data
for December of the previous year. This "DatePart
("yyyy",Now())" won't work in Jan.

Try using:
Month(DateSerial(Year(Date()), Month(Date()) - 1, 1))
Year(DateSerial(Year(Date()), Month(Date()) - 1, 1))
 

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