Solved

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

Posted on 2015-01-03
4
212 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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 …

840 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