Saving two reports into one PDF (1 Viewer)

crann

Registered User.
Local time
Today, 10:04
Joined
Nov 23, 2002
Messages
160
Hi

I use the following code to save a report as a pdf to my desktop. All works fine.

At the moment it save the report: rptDevPackPage1
I want it to also include: rptDevPackPage2

but only create one saved pdf with both pages on.

In summary save two reports into one pdf file.

Is the possible. I managed to find the exisiting code online and tried to add the name of the second rpt I wanted but just get errors.

Thanks

Code:
Private Sub Command132_Click()
Dim FileName As String
Dim FilePath As String
Dim UserLogin As String
On Error GoTo My_ErrorHandler:

UserLogin = Environ("UserName")
FileName = "DevelopmentPack"

FilePath = "C:\Users\Jonathan\Desktop\" & FileName & ".pdf"
'DoCmd.OutputTo acOutputForm, "tbl_customer", acFormatPDF, FilePath
DoCmd.OutputTo acOutputReport, "rptDevPackPage1", acFormatPDF, FilePath
MsgBox "Development Pack has been successfully saved as a PDF to Desktop", vbInformation, "Save confirmed"

exit_My_ErrorHandler:
    Exit Sub
My_ErrorHandler:
    MsgBox "Error # :" & err.Number & ", " & err.Description, vbExclamation
    Resume Next
End Sub
 

Ranman256

Well-known member
Local time
Today, 05:04
Joined
Apr 9, 2015
Messages
4,337
You don't need any code...
Just both reports as sub reports into a main report.
Then print to PDF.
 

crann

Registered User.
Local time
Today, 10:04
Joined
Nov 23, 2002
Messages
160
Thanks

So simple. Didn't even realise I could add a sub report.

I have just also realised that I have no code that will let me print the report specific to the record in the form I am in.

Would this be difficult to add to my existing code I uploaded. I do have an ID field would that help?

Thanks again
 

Ranman256

Well-known member
Local time
Today, 05:04
Joined
Apr 9, 2015
Messages
4,337
add the code to a button click.
but use the subreport version to get them both in 1 rpt.
 

crann

Registered User.
Local time
Today, 10:04
Joined
Nov 23, 2002
Messages
160
Ok so I have created the Cmd and used the follwoing code again to save the main report which contains the sub reports to a PDF onto desktop.

Thats working fine, thanks so much.

Now all I need to do is get the report to print based on the record I am in so linked to the ID of each individual record, at the moment regardless of what record I am in it just prints the report for the first record in the table.

Any help be grateful

Thanks

Code:
Private Sub Command132_Click()

    Dim FileName As String
Dim FilePath As String
Dim UserLogin As String
On Error GoTo My_ErrorHandler:

UserLogin = Environ("UserName")
FileName = "DevelopmentPack"

FilePath = "C:\Users\Jonathan\Desktop\" & FileName & ".pdf"

DoCmd.OutputTo acOutputReport, "rptMainReport", acFormatPDF, FilePath

MsgBox "Development Pack has been successfully saved as a PDF to Desktop", vbInformation, "Save confirmed"

exit_My_ErrorHandler:
    Exit Sub
My_ErrorHandler:
    MsgBox "Error # :" & err.Number & ", " & err.Description, vbExclamation
    Resume Next
End Sub
 

Users who are viewing this thread

Top Bottom