Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / April 2007

Tip: Looking for answers? Try searching our database.

Prevent Report from being set to a printer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GTajos - 19 Apr 2007 20:40 GMT
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
Ed Metcalfe - 19 Apr 2007 21:16 GMT
>I have a report in a collection of reports for which previewing is handy
>but
[quoted text clipped - 5 lines]
> 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.
GTajos - 19 Apr 2007 22:08 GMT
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

> >I have a report in a collection of reports for which previewing is handy
> >but
[quoted text clipped - 20 lines]
>
> Ed Metcalfe.
Marshall Barton - 19 Apr 2007 22:15 GMT
>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.

Signature

Marsh
MVP [MS Access]

GTajos - 19 Apr 2007 22:36 GMT
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

> >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.
[quoted text clipped - 7 lines]
> in the Activate event.  Then close the report in the report
> header section's format event if the variable is not set.
GTajos - 19 Apr 2007 23:42 GMT
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
GTajos - 20 Apr 2007 01:52 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.