Solved

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

Posted on 2015-01-03
4
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Remove Selected Values from Access Combobox 2 35
Undo Button 1 35
Database maintenance 36 110
Using Access multi Listbox to pass criteria to a query 9 31
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

730 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