Save multiple reports to PDF (1 Viewer)

urjudo

Member
Local time
Yesterday, 18:07
Joined
Oct 9, 2020
Messages
67
Hello,
I have a question how to save multiple reports to PDF. How do I save them into individual page by order# instead save them all into one page by individual order#? I have a form that users enter Order date and Location. When I click Save Reports, if I have four order#, it save four reports but each report combined all four reports together. Is any way I can save as individual Report? Any help would be grate appreciate!

Here are my code:
Code:
Option Compare Database
Option Explicit
Dim RecordOne as Boolean
Dim stDocName as string
Dim NumberofRecords as Integer
Dim FilePath as String

Private Sub MoveToNextRecord()
   DoCmd.GoToRecord, , acNext

Private Sub SavetheRecord()
FilePath = Environ("UserProfile") & "\OneDrive\Order\"

If Me.Location = "PA"
   stDocName = "rptOrderA
   DoCmd.OutPutTo acOutputReport, "rptOrderA", acFormatPDF, FilePath & Me.Docket & "-rptOrderA.pdf"

   stDocName = "rptOrderB
   DoCmd.OutPutTo acOutputReport, "rptOrderB", acFormatPDF, FilePath & Me.Docket & "-rptOrderA.pdf"
Else 
    stDocName = "rptOrderA
    DoCmd.OutPutTo acOutputReport, "rptOrderA", acFormatPDF, FilePath & Me.Docket & "-rptOrderA.pdf"
End if

Private Sub SaveReports_Click()
On Error GoTo Err_SaveReports_Click
FilePath = Environ("UserProfile") & "\OneDrive\Order\"

For x= 1 To NumberofRecords
      SavetheRecord
      If x < NumberofRecords then
             MoveToNextRecord
     End if
Next x

stDocName = "rptConfirmLetter"
 DoCmd.OutPutTo acOutputReport, "rptConfirmLetter", acFormatPDF, FilePath & Me.Docket & "-rptOrderA.pdf"

DoCmd.Close acForm, "frmOrderBatch"

Exit_SaveReports_Click:
    Exit Sub
Err_SaveReports_Click:
   Msgbox Err.Description
   Resume Exit_SaveReports_Click
End Sub

Thank you for your time!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:07
Joined
Oct 29, 2018
Messages
21,467
Hi. Not sure I fully understand the situation, but it sounds like you want to create a loop, so you can create/save a single report/pdf on each pass in the loop.
 

urjudo

Member
Local time
Yesterday, 18:07
Joined
Oct 9, 2020
Messages
67
@theDBguy ,
Yes, that's exactly what I want. Sometimes there are 10 orders in one OrderDate. For example, if user enter 12/7/20, Dept: Fiscal (sorry on the description I put Location, it should be dept, but the code is correct for the location). so it might have 5 different order#, each report would have it's own order#, I want to be able to save each report with it's owe order# once and not five time with all the report together and in different order#. Hope I explanation clear. Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:07
Joined
Oct 29, 2018
Messages
21,467
@theDBguy ,
Yes, that's exactly what I want. Sometimes there are 10 orders in one OrderDate. For example, if user enter 12/7/20, Dept: Fiscal (sorry on the description I put Location, it should be dept, but the code is correct for the location). so it might have 5 different order#, each report would have it's own order#, I want to be able to save each report with it's owe order# once and not five time with all the report together and in different order#. Hope I explanation clear. Thanks
Right. So, you could try setting up a recordset of all the records you want to print and then loop through each one and create separate PDFs.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:07
Joined
Oct 29, 2018
Messages
21,467
@theDBguy ,
Sorry, how to I set up a recordset for that?
Sorry as well. Since we cannot see your database, we can only give you ideas. I can't give you exact instructions on how to create something that will work for your situation. As an example though, here's how you might create a recordset.
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT * FROM TableName WHERE SomeField='SomeCriteria'"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)

With rs
    Do While Not .EOF
        'do something with this record
        .MoveNext
    Loop
    .Close
End With

Set rs = Nothing
Set db = Nothing
Hope that helps...
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 00:07
Joined
Jul 9, 2003
Messages
16,280
I answered a similar question a while back, and I placed it on my blog here:-


The blog and videos might give you some idea of how to develop something similar yourself.

There is a downloadable example file is available for free to Access World Forum members. Contact me for details on how to get it for free ...
 

urjudo

Member
Local time
Yesterday, 18:07
Joined
Oct 9, 2020
Messages
67
@theDBguy , Thanks for the example!
@Uncle Gizmo , great info but do I have to create table for it or if anyway I don't need to use a table? Thanks!
 

Users who are viewing this thread

Top Bottom