help Output to PDF for selected value

S

SF

Hi,

I have a form with the following controls:

a listbox to display Contract #
a listbox of report name
a button to export to PDF

For Each varItem In Me.cmbContractNumber.ItemsSelected
StgCriteria = "[Ck_ContractID]='" &
Me.cmbContractNumber.ItemData(varItem) & "'"
PDFFileName = Me.cmbContractNumber.ItemData(varItem) & ".pdf"
Debug.Print Me.listReports; StgCriteria
DoCmd.OutputTo acOutputReport, Me.listReports, acFormatPDF,
PDFFileName, -1
Next varItem

It seem that all records was outputed to PDF, how can I tell Access to
output only select Contract item in the list

SF
 
A

Arvin Meyer [MVP]

The report, lin in, must only open to 1 records to use it that way. So set
the recordsource to be a report with the parameter of the Key value from the
form. Then send it as a PDF.
 
A

Arvin Meyer [MVP]

That should read:

The report, in listReports, must only open to 1 record to use it that way.
So set
the recordsource to be a report with the parameter of the Key value from
the
form. Then send it as a PDF.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


Arvin Meyer said:
The report, lin in, must only open to 1 records to use it that way. So set
the recordsource to be a report with the parameter of the Key value from
the form. Then send it as a PDF.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


SF said:
Hi,

I have a form with the following controls:

a listbox to display Contract #
a listbox of report name
a button to export to PDF

For Each varItem In Me.cmbContractNumber.ItemsSelected
StgCriteria = "[Ck_ContractID]='" &
Me.cmbContractNumber.ItemData(varItem) & "'"
PDFFileName = Me.cmbContractNumber.ItemData(varItem) & ".pdf"
Debug.Print Me.listReports; StgCriteria
DoCmd.OutputTo acOutputReport, Me.listReports, acFormatPDF,
PDFFileName, -1
Next varItem

It seem that all records was outputed to PDF, how can I tell Access to
output only select Contract item in the list

SF
 
K

Ken Sheridan

You are not passing the criterion to the report. This can be done by means
of a parameter in the report's underlying query, but as you appear to be
using a multi-select list box (though its name, cmbContractNumber, is rather
confusing for this type of control, suggesting a combo box), you cannot
reference the list box directly as the parameter, so you'll need to assign
each ContractID value to a hidden (Visible property = False) text box on the
form at each iteration of the loop through the list box's ItemsSelected
collection. The hidden text box can then be referenced as a parameter for
the ContractID column in each report's query like this:

Forms![YourForm]![YourHiddenTextBox]

The code in the button's Click event procedure would be:

Dim varItem As Variant
Dim PDFFileName As String
Dim strContractID As String

For Each varItem In Me.cmbContractNumber.ItemsSelected
strContractID = Me.cmbContractNumber.ItemData(varItem)
Me.YourHiddenTextBox = strContractID
PDFFileName = strContractID & ".pdf"
DoCmd.OutputTo acOutputReport, Me.listReports, _
acFormatPDF, PDFFileName, True
Next varItem

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top