ExpressMan1
asked on
Save Report to PDF file and set filename to value on continuous form where check box = true
The following code works but is setting the file name to the first record showing on the continuous form. There is a checkbox "SelectInvoice" for each record showing on the form and I am trying to get it to set the filename to the record where the checkbox is True.
Private Sub cmdSaveToPDF_Click()
Dim FileName As String
Dim FilePath As String
FileName = Me.Company & " " & "Invoice " & Me.InvoiceNumber
FilePath = "C:\Users\John\Documents\I nvoices\" & FileName & ".pdf"
DoCmd.OutputTo acOutputReport, "rptInvoice", acFormatPDF, FilePath
MsgBox "Invoice PDF has been saved.", vbInformation, "Save Confirmed"
End Sub
Do I need to use an SQL statement to refer to the underling table where the value of checkbox is true?
Private Sub cmdSaveToPDF_Click()
Dim FileName As String
Dim FilePath As String
FileName = Me.Company & " " & "Invoice " & Me.InvoiceNumber
FilePath = "C:\Users\John\Documents\I
DoCmd.OutputTo acOutputReport, "rptInvoice", acFormatPDF, FilePath
MsgBox "Invoice PDF has been saved.", vbInformation, "Save Confirmed"
End Sub
Do I need to use an SQL statement to refer to the underling table where the value of checkbox is true?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As Rey said, the code you're showing would work on the "focused" or "selected" record only. If you want to run this action for each of the selected records in your form, then you'd have to use a query to do that:
Dim rst As DAO.Recordset
Set rst = Currentdb.OpenRecordset("SELECT * FROM YourTable WHERE Selected=True")
Dim FileName As String
Dim FilePath As String
Do Until rst.EOF
FileName = Me.Company & " " & "Invoice " & Me.InvoiceNumber
FilePath = "C:\Users\John\Documents\Invoices\" & FileName & ".pdf"
DoCmd.OutputTo acOutputReport, "rptInvoice", acFormatPDF, FilePath
Loop
MsgBox "Invoice PDF has been saved.", vbInformation, "Save Confirmed"
Of course, you'd have to change the Table and Field names to fit your project.
ASKER
Thank You All. I can't believe I missed that!!
You don't need to use a SQL statement, but the way for getting values for a control depends on what kind of control do you have.