Solved

Save Report to PDF file and set filename to value on continuous form where check box = true

Posted on 2015-01-03
4
209 Views
Last Modified: 2015-01-04
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\Invoices\" & 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?
0
Comment
Question by:ExpressMan1
4 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 40529916
I don't fully understand your quen. Is it company a textbox? If so, change me.conpamy by me.company.text and also me.invoicenumber to me.invoiceNumber.text

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.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40529965
try selecting the record first before clicking the button cmdSaveToPDF

the reason why it is getting the first record is, the first record is the one on focus or selected.
0
 
LVL 84
ID: 40530019
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"

Open in new window

Of course, you'd have to change the Table and Field names to fit your project.
0
 

Author Closing Comment

by:ExpressMan1
ID: 40530299
Thank You All. I can't believe I missed that!!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question