Reports to PDF - Folder location

G

Guest

I'm using code I've found around this newsgroup and elsewhere to automate
printing my Access reports to PDF. I need help when it comes to defining the
report path. These are monthly production reports that go to a location that
changes each month. The folders are named 2006_01, 2006_02, 2006_03 etc..
They update each month for the preceding month. So at the beginning of next
month they will need to save to the folder 2006_03 (We produce reports within
the first 15 days for the previous month).

It will need to look at the month of today's date to determine whether it's
January so it can set the year to the previous year. It will need to check
if the day of the month is less than 15. If so the month of the folder is
the previous month. If it's greater than 15 it would be the current month.

Does anyone know how to code this in VB or have similar code that I might be
able to use to figure it out?

Thanks,
MARs
 
G

Guest

This function will meet the rules you posted. Just call it like this to
build that part of your path:

strPathDatePart = ReportPath(date)

Rather than hard code Date in the function, I did this to allow for create
paths for dates in the past or future.

Function ReportPath(dtmRptDate As Date) As String
Dim intYr As Integer
Dim intMo As Integer
Dim intDay As Integer

intDay = Day(dtmRptDate)
intMo = Month(dtmRptDate)
intYr = year(dtmRptDate)
intYr = IIf(intMo = 1 And intDay <= 15, intYr - 1, intYr)
intMo = IIf(intDay <= 15, intMo - 1, intMo)
intMo = IIf(intMo = 0, 12, intMo)
ReportPath = Format(intYr, "0000") & "_" & Format(intMo, "00")

End Function
 
G

Guest

Thanks!! I'll try this.
--
Thanks,
MARs


Klatuu said:
This function will meet the rules you posted. Just call it like this to
build that part of your path:

strPathDatePart = ReportPath(date)

Rather than hard code Date in the function, I did this to allow for create
paths for dates in the past or future.

Function ReportPath(dtmRptDate As Date) As String
Dim intYr As Integer
Dim intMo As Integer
Dim intDay As Integer

intDay = Day(dtmRptDate)
intMo = Month(dtmRptDate)
intYr = year(dtmRptDate)
intYr = IIf(intMo = 1 And intDay <= 15, intYr - 1, intYr)
intMo = IIf(intDay <= 15, intMo - 1, intMo)
intMo = IIf(intMo = 0, 12, intMo)
ReportPath = Format(intYr, "0000") & "_" & Format(intMo, "00")

End Function
 

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