I'm now working on building a macro tied to a button on the Form that will run and print all of the needed reports to a PDF...another challenge, but I think I found articles on how to print to PDF and automatically
save to the correct place.
On this issue you might like to take a look at Invoice.zip in my public databases folder at:
https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to amend the form design accordingly.
If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.
In this little demo file the code (I doubt this would be possible with a macro) for outputting the multiple invoices to separate files is as follows:
Private Sub cmdCreateInvoices_MultiFiles_Click()
On Error GoTo Err_Handler
Const FOLDER_EXISTS = 75
Const MESSAGE_TEXT_1 = "No folder set for storing PDF files."
Const MESSAGE_TEXT_2 = "No invoice(s) selected."
Dim strFullPath As String
Dim varFolder As Variant
Dim varFolder_1 As Variant
Dim varItem As Variant
' build path to save PDF file
varFolder = DLookup("Folderpath", "pdfFolder")
If IsNull(varFolder) Then
MsgBox MESSAGE_TEXT_1, vbExclamation, "Invalid Operation"
Else
With Me.lstInvoices
If .ItemsSelected.Count > 0 Then
For Each varItem In .ItemsSelected
Me.txtInvoiceList = .ItemData(varItem)
' create folder if does not exist
varFolder_1 = varFolder & "" & .Column(1, varItem)
MkDir varFolder_1
strFullPath = varFolder_1 & "" & .Column(1, varItem) & " " & .ItemData(varItem) & ".pdf"
DoCmd.OutputTo acOutputReport, "rptInvoiceMultiple", acFormatPDF, strFullPath, True
Next varItem
Else
MsgBox MESSAGE_TEXT_2, vbExclamation, "Invalid Operation"
End If
End With
End If
Exit_Here:
Exit Sub
Err_Handler:
Select Case Err.Number
Case FOLDER_EXISTS
Resume Next
Case Else
MsgBox Err.Description
Resume Exit_Here
End Select
End Sub
I 'd draw your attention to this line in particular:
Me.txtInvoiceList = .ItemData(varItem)
What this does is assign the invoice number to a hidden text box control in the form. The reason it is named txtInvoiceList is because another option in the form is to output multiple invoices to a single PDF file, in which case the control is assigned a list
of invoice numbers. In both cases the control is referenced as a parameter by the report's query, restricting the report to the specific invoice (in the above code) or to multiple selected invoices (in another button's code). As your reports reference parameters,
you could do similarly by making those parameters references to hidden controls in the form from which the reports are opened. The key thing is that a different value is assigned to the parameter before outputting the report to a PDF file each time, so in
your case you would need to do similarly, but not on the basis of a multi-select list box, as in my case. You would, if I understand your set-up correctly, loop through nested recordsets of months and salespeople.