Printing all Reports Function (1 Viewer)

chriscardwell06

Registered User.
Local time
Today, 04:10
Joined
Aug 18, 2011
Messages
38
I have a form that shows our manufacturing schedule. It has a sub query in it that you select which operation you want to preview the data for. It loads the data in another sub query in which I have a button that will print that data. The sub query on the left is labeled qProdHrs5bRS2. The query that loads the manufacturing schedule for that operation is labeled Manf_Resource_ByDate. I can hard code a button that goes through each operation and then print them. The issue with that is that if a user ever adds an operation to the operations table I would have to go edit this each time. I want to make this function see the report of operations and then proceed to make each one active and print it's report. Then move on to the next resource in the table until it runs out of resources. That way a user doesn't have to sit there and individually print all 30ish reports one at a time. I've added a screen shot of what the manufacturing schedule form looks like. Any help for this would be greatly appreciated.
1620139757318.png
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:10
Joined
Oct 29, 2018
Messages
14,875
Hi. Maybe you can use a recordset object and loop through it to print your data.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:10
Joined
Sep 21, 2011
Messages
8,025
I am sure that means a lot to you, unfortunately nothing to me? :(

I'd have a table that somehow links the reports with the operations, then process that table for the relevant operation.?
 

chriscardwell06

Registered User.
Local time
Today, 04:10
Joined
Aug 18, 2011
Messages
38
I am open to either one of those options if it gets me where I need to go. But I'm not entirely sure how to do those things. I have all the data and tables to say print report using record 1 from table as operation but then I need it to repeat all the way through the operations. I hope I'm making sense here.
 

bastanu

Active member
Local time
Today, 01:10
Joined
Apr 13, 2010
Messages
743
Have a look at the included code that would export individual reports as PDF; replace the OutputTo with Docmd.OpenReport acviewnormal to print
Code:
Public lCurrentID_Record As Long  'place this at the top of a standard module

Public Function vcCurrentID_Record() As Long 'place this at the top of a standard module
vcCurrentID_Record= lCurrentID_Record
'use this function in a new query based on your existing report record source
'place the function in the criteria row of the PK ID to return one record at the time
End Function

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<this is the code for the export button on your form>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Private Sub cmdExportPDF_Click()

On Error GoTo Err_cmdExportPDF_Click

Dim rst As DAO.Recordset
DIm sFileName as string

Set rst = CurrentDb.OpenRecordset("qryYourExistingReportRecordSource", dbOpenSnapshot) 'this is the existing query returning all records to be exported

On Error Resume Next

DoCmd.Close acReport, "rptYourReportFiltered" 'this is a copy of your existing report with the new recordsource returning one record at the time using the public function above

lCurrentID_Record = 0

Do Until rst.EOF
        lCurrentID_Record = rst("[PK_ID]") 'replace PK_ID with your own unique ID
    sFileName="BuildYourFileNameUsingACommonPathAndUniqueInfoFromTheRecordset"   
        DoCmd.OutputTo acOutputReport, "rptYourReportFiltered" , "PDF Format (*.pdf)", sFileName, False
 
rst.MoveNext
Loop

rst.Close
Set rst = Nothing

Exit_cmdExportPDF_Click:
    Exit Sub

Err_cmdExportPDF_Click
    MsgBox Err.Description
    Resume Exit_cmdExportPDF_Click
End Sub
Obviously you will need to adjust the code to match your table and field names.
Cheers,
 

chriscardwell06

Registered User.
Local time
Today, 04:10
Joined
Aug 18, 2011
Messages
38
Have a look at the included code that would export individual reports as PDF; replace the OutputTo with Docmd.OpenReport acviewnormal to print
Code:
Public lCurrentID_Record As Long  'place this at the top of a standard module

Public Function vcCurrentID_Record() As Long 'place this at the top of a standard module
vcCurrentID_Record= lCurrentID_Record
'use this function in a new query based on your existing report record source
'place the function in the criteria row of the PK ID to return one record at the time
End Function

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<this is the code for the export button on your form>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Private Sub cmdExportPDF_Click()

On Error GoTo Err_cmdExportPDF_Click

Dim rst As DAO.Recordset
DIm sFileName as string

Set rst = CurrentDb.OpenRecordset("qryYourExistingReportRecordSource", dbOpenSnapshot) 'this is the existing query returning all records to be exported

On Error Resume Next

DoCmd.Close acReport, "rptYourReportFiltered" 'this is a copy of your existing report with the new recordsource returning one record at the time using the public function above

lCurrentID_Record = 0

Do Until rst.EOF
        lCurrentID_Record = rst("[PK_ID]") 'replace PK_ID with your own unique ID
    sFileName="BuildYourFileNameUsingACommonPathAndUniqueInfoFromTheRecordset"  
        DoCmd.OutputTo acOutputReport, "rptYourReportFiltered" , "PDF Format (*.pdf)", sFileName, False

rst.MoveNext
Loop

rst.Close
Set rst = Nothing

Exit_cmdExportPDF_Click:
    Exit Sub

Err_cmdExportPDF_Click
    MsgBox Err.Description
    Resume Exit_cmdExportPDF_Click
End Sub
Obviously you will need to adjust the code to match your table and field names.
Cheers,
I'll get to work on adding that in. I believe I'm following where you're going. Obviously the button code is in the on click event. Where do I place the code for the public function?
 

bastanu

Active member
Local time
Today, 01:10
Joined
Apr 13, 2010
Messages
743
Add the public variable and public function in any new or existing standard module.

Cheers,
 

Users who are viewing this thread

Top Bottom