Link to home
Start Free TrialLog in
Avatar of D J
D JFlag for United States of America

asked on

MS Access How can I convert my VBA code from print preview to PDF output?

How can I convert my VBA code (see below) from print preview to PDF output?


Private Sub Command68_Click()
Dim var As Variant
Dim where As String

For Each var In Me.List66.ItemsSelected

  where = Me.List66.ItemData(var) & "," & where
Next var

If Len(where) > 0 Then
    where = Left(where, Len(where) - 1)
    DoCmd.OpenReport "rpt_SW_Report_By_H", acViewPreview, , "lc_craftsid IN (" & where & ")"
End If
End Sub

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

what is the Record Source of the report?
if it is a query, post the SQL statement of the query.
if it is a table, create a query against the table, then use the query as the Record Source of the report  and post the SQL statement  of the query.

better if you can upload a copy of the db. (will save more time posting back and forth)
Insert a one code line to print to PDF:

If Len(where) > 0 Then
    where = Left(where, Len(where) - 1)
    DoCmd.OpenReport "rpt_SW_Report_By_H", acViewPreview, , "lc_craftsid IN (" & where & ")"
    DoCmd.OutputTo acOutputReport, "", acFormatPDF, "C:\Test\rpt_SW_Report_By_H.pdf", False
End If

Open in new window

/gustav
Avatar of D J

ASKER

Thanks Gustav,
How do I stop the print preview from displaying with the PDF?
(would like to display PDF only)
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of D J

ASKER

Thanks Gustav,

It flashes on the screen, should be OK.
Avatar of D J

ASKER

Thanks Gustav!
You are welcome!

/gustav