Prevent Report from being set to a printer

G

Guest

I have a report in a collection of reports for which previewing is handy but
we do not want to print it as it is 125 pages long.

Does anyone know of code that will keep this report from being sent to a
printer?


Thanks,
Garry
 
E

Ed Metcalfe

GTajos said:
I have a report in a collection of reports for which previewing is handy
but
we do not want to print it as it is 125 pages long.

Does anyone know of code that will keep this report from being sent to a
printer?


Thanks,
Garry

Garry,

I would:

1. Remove the menu bar that contains the print command (either throughout
the whole database, or just when this report is open - personally I'd remove
globally).

2. Create your own Print toolbar and set this as toolbar for all reports you
want to be printable.

3. Disable the Ctrl+P keyboard shortcut with an AutoKeys macro.

Ed Metcalfe.
 
G

Guest

Ed,

My apologies! I use the technique you posted in a lot of the bigger
projects. This is a simple small project and I was looking for a simple
solution. I have needed this simple solution many a time as I do a lot of
these quick and mostly clean projects.

It seems that the following code produces the out come I was looking for:
( All of this is in the Report Module)

Option Compare Database

Public FrmtCnt As Integer

Private Sub Report_Open(Cancel As Integer)
FrmtCnt = 0
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
FrmtCnt = FrmtCnt + 1
End Sub

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
If FrmtCnt > 2 Then
Cancel = True
Reports(Me.Name).Printer.Copies = 0
End If
End Sub


1) I verified that this report requires 2 passes for the ReportHeader_Format
2) I am not sure how the windows print dialog deals with the
Num Copies being set to 0, But I do not get any errors and the report does
not print.

Thanks,
Garry
 
M

Marshall Barton

GTajos said:
I have a report in a collection of reports for which previewing is handy but
we do not want to print it as it is 125 pages long.

Does anyone know of code that will keep this report from being sent to a
printer?


In addition the Ed's advice about printing from the preview
window, you can prevent the report from being opened
directly to the printer by setting a module level variable
in the Activate event. Then close the report in the report
header section's format event if the variable is not set.
 
G

Guest

Marshall,
Thanks, I was just adding that in. The code now:
1) allows the report to be previewed
2) does not allow it to be sent directly to the print
3) does not allow being printed from any of the print buttons
4) If the user tried to print the report, the report will notify the user
that it did not
print when the user closes the report.


Public FrmtCnt As Integer
Public RptPrt As Boolean

Private Sub Report_Activate()
RptPrt = False
End Sub

Private Sub Report_Close()
If FrmtCnt > 3 Then
MsgBox vbCr & "This Report Contains Way To Many Pages to Print" & _
vbCr & vbCr & " Print Was Canceled!" & vbCr
End If
End Sub

Private Sub Report_NoData(Cancel As Integer)
MsgBox vbCr & "There is no data for this report." & vbCr & vbCr & _
" Canceling report..." & vbCr & vbCr
Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
FrmtCnt = 0
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
If RptPrt = False Then
DoCmd.Close acReport, Me.Name, acSaveNo
End If
FrmtCnt = FrmtCnt + 1
End Sub

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
If FrmtCnt > 2 Then
Cancel = True
Reports(Me.Name).Printer.Copies = 0
End If
End Sub
 
G

Guest

Ok, as usual haste makes waste. The previously posted code does not work!

Here is the code that actually works:

Option Compare Database
Public FrmtCnt As Integer

Private Sub Report_Close()
If FrmtCnt > 3 Then
MsgBox vbCr & "This Report Contains Way To Many Pages to Print" & _
vbCr & vbCr & " Print Was Canceled!" & vbCr
End If
End Sub

Private Sub Report_NoData(Cancel As Integer)
MsgBox vbCr & "There is no data for this report." & vbCr & vbCr & "
Canceling report..." & vbCr & vbCr
Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
If IsNull(Me.OpenArgs) Then
Cancel = True
End If
FrmtCnt = 0
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
FrmtCnt = FrmtCnt + 1
End Sub

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
If FrmtCnt > 2 Then
Cancel = True
Reports(Me.Name).Printer.Copies = 0
End If
End Sub


The only way to get the report to open in preview is to issue the following
from a module other than the reports own.

DoCmd.OpenReport "PreviewOnlyFrm", acViewPreview, , , acWindowNormal,
"PrViewOnly"

The OpenArgs does not need to be “PrViewOnly “. It can be anything but NULL.

Have Fun,
Garry
 
G

Guest

One last tweak to resolve the error that occurred when scrolling thru pages
then returning back to page 1.


Option Compare Database
Public FrmtCnt As Integer

Private Sub Report_Close()
If FrmtCnt > 3 Then
MsgBox vbCr & "This Report Contains Way To Many Pages to Print" & _
vbCr & vbCr & " Print Was Canceled!" & vbCr
End If
End Sub

Private Sub Report_NoData(Cancel As Integer)
MsgBox vbCr & "There is no data for this report." & vbCr & vbCr & "
Canceling report..." & vbCr & vbCr
Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
If IsNull(Me.OpenArgs) Then
Cancel = True
MsgBox vbCr & "This Report can only be opened from a form"
End If
FrmtCnt = 0
End Sub

Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As Integer)
FrmtCnt = 0
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
FrmtCnt = FrmtCnt + 1
End Sub

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
If FrmtCnt > 2 Then
Cancel = True
Reports(Me.Name).Printer.Copies = 0
End If
End Sub




After all of that I must concede at this point and say Ed’s original
solution is the most reliable that I know of.
Why couldn’t the developers give use a OnPrint or BeforePrint event for the
Report?


Thanks for appeasing the stubborn,
Garry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top