In the form, the code get the report, vRpt, from lstRpts
and the vDept from the lstDepts
Code:
Public Sub ReportOutput()
Dim vDate, vRpt, vDept, vDir, vTargDir, vType, vFile, vRptName
Dim r, d
vDate = Format(Date, "yymmdd")
vType = cboRptType 'weekly, daily, monthly
vDir = DLookup("[RptDir]", "tConfig") 'lookup report folder to print to
For r = 1 To lstRpts
vRpt = lstRpts(r).ItemData 'get next rpt
For d = 1 To lstDepts
vDept = lstDepts(d).ItemData 'get next dept
vTargDir = vDir & vDept & "\"
MakeDir vTargDir 'ignores if exists
vRptName = vRpt & "-" & vDept & "-" & vType & vDate & ".pdf"
vFile = vTargDir & vRptName
DoCmd.OutputTo acOutputReport, vRpt, acFormatPDF, vFile
Next
Next
End Sub
Public Sub MakeDir(ByVal pvDir)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(pvDir) Then fso.CreateFolder pvDir 'MkDir pvDir
Set fso = Nothing
End Sub