M
m2
I work for a law enforcement agency and have created a database to do
our reports. One of our reports is an operations report that could
have supplemental reports and use of force reports "attached" to it
through an autonumber. If officers fill out a supplemental report,
they can also have a use of force attached to the supplemental report.
All is working and I can print each report separately. I want to
create a function that will allow me to print all reports attached to
the main operations report, to include the proper page header/footer
for each report (as operations/supplemental reports can be multiple
pages per report).
Problem: I have an 'AutoNum' field for each report, and the
supplemental and use of force have an 'AutoFromOR' fields that point
back to the operations report, and the use of force can also link back
to a supplemental report if created from that supplemental.
Desired solution: I would like to click the command button and open
each report, print each according to their AutoNum or AutoFromOR
fields, choose the printer to send it to and then print each one.
Code:
Dim stDocName As String, stWhere As String, stSupp As String, _
stUOF As String, stWSupp As String, stWUOF As String, stUOFSupp As
String, _
stWUOFSupp As String
If Me.Dirty Then Me.Dirty = False
stDocName = "OperationsReport"
stWhere = "SELECT AutoNum FROM " & stDocName & " WHERE AutoNum = "
& Me.AutoNum
stSupp = "SuppReport"
stWSupp = "SELECT AutoFromOR FROM " & stDocName & " WHERE
AutoFromOR = " & Me.AutoNum
stUOF = "UseOfForce"
stWUOF = "SELECT AutoFromOR FROM " & stDocName & " WHERE
AutoFromOR = " & Me.AutoNum
stUOFSupp = "UseOfForce"
stWUOFSupp = "SELECT AutoFromOR FROM " & stDocName & " WHERE
AutoFromOR = " & Me.AutoNum
DoCmd.OpenReport stDocName, acPreview, stWhere, , acIcon
DoCmd.OpenReport stSupp, acPreview, stWSupp, , acIcon
DoCmd.OpenReport stUOF, acPreview, stWUOF, , acIcon
DoCmd.OpenReport stWUOF, acPreview, stWUOFSupp, , acIcon
DoCmd.SelectObject acReport, stDocName, False
DoCmd.RunCommand acCmdPrint
DoCmd.SelectObject acReport, stSupp, False
DoCmd.RunCommand acCmdPrint
DoCmd.SelectObject acReport, stUOF, False
DoCmd.RunCommand acCmdPrint
DoCmd.SelectObject acReport, stUOF, False
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, stDocName, acSaveNo
DoCmd.Close acReport, stSupp, acSaveNo
DoCmd.Close acReport, stUOF, acSaveNo
DoCmd.Close acReport, stUOF, acSaveNo
Any help for my brainfart would be greatly appreciated.
our reports. One of our reports is an operations report that could
have supplemental reports and use of force reports "attached" to it
through an autonumber. If officers fill out a supplemental report,
they can also have a use of force attached to the supplemental report.
All is working and I can print each report separately. I want to
create a function that will allow me to print all reports attached to
the main operations report, to include the proper page header/footer
for each report (as operations/supplemental reports can be multiple
pages per report).
Problem: I have an 'AutoNum' field for each report, and the
supplemental and use of force have an 'AutoFromOR' fields that point
back to the operations report, and the use of force can also link back
to a supplemental report if created from that supplemental.
Desired solution: I would like to click the command button and open
each report, print each according to their AutoNum or AutoFromOR
fields, choose the printer to send it to and then print each one.
Code:
Dim stDocName As String, stWhere As String, stSupp As String, _
stUOF As String, stWSupp As String, stWUOF As String, stUOFSupp As
String, _
stWUOFSupp As String
If Me.Dirty Then Me.Dirty = False
stDocName = "OperationsReport"
stWhere = "SELECT AutoNum FROM " & stDocName & " WHERE AutoNum = "
& Me.AutoNum
stSupp = "SuppReport"
stWSupp = "SELECT AutoFromOR FROM " & stDocName & " WHERE
AutoFromOR = " & Me.AutoNum
stUOF = "UseOfForce"
stWUOF = "SELECT AutoFromOR FROM " & stDocName & " WHERE
AutoFromOR = " & Me.AutoNum
stUOFSupp = "UseOfForce"
stWUOFSupp = "SELECT AutoFromOR FROM " & stDocName & " WHERE
AutoFromOR = " & Me.AutoNum
DoCmd.OpenReport stDocName, acPreview, stWhere, , acIcon
DoCmd.OpenReport stSupp, acPreview, stWSupp, , acIcon
DoCmd.OpenReport stUOF, acPreview, stWUOF, , acIcon
DoCmd.OpenReport stWUOF, acPreview, stWUOFSupp, , acIcon
DoCmd.SelectObject acReport, stDocName, False
DoCmd.RunCommand acCmdPrint
DoCmd.SelectObject acReport, stSupp, False
DoCmd.RunCommand acCmdPrint
DoCmd.SelectObject acReport, stUOF, False
DoCmd.RunCommand acCmdPrint
DoCmd.SelectObject acReport, stUOF, False
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, stDocName, acSaveNo
DoCmd.Close acReport, stSupp, acSaveNo
DoCmd.Close acReport, stUOF, acSaveNo
DoCmd.Close acReport, stUOF, acSaveNo
Any help for my brainfart would be greatly appreciated.