Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Knowing when a report is Previewing vs Printing?

2 views
Skip to first unread message

Tony Toews

unread,
Mar 24, 2000, 3:00:00 AM3/24/00
to
Folks

We have a situation where we would like to take some action when a report is being
printed. The user will preview the report several times but when its being printed
we want take some action. (Actually we're going to email the report as well as print
it but only when printed..)

However I'm unable to find any method of determining, in code, if the report is being
previewed or printed. Maybe I'm overlooking the obvious. <smile>

I came across http://support.microsoft.com/support/kb/articles/Q154/8/94.asp titled
How to Maintain a Print Log for Reports however this chunk of code makes no sense as
the mechanism and doesn't work for me either.

Thanks, Tony
----
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
VolStar http://www.volstar.com Manage hundreds or
thousands of volunteers for special events.

Terry Wickenden

unread,
Mar 24, 2000, 3:00:00 AM3/24/00
to
There is no "Print" event. I presume that you are hoping to catch the people
who print from Print Prview. The only way I can think to do that is to
create your own toolbar/menubar for the report. Then you will know when the
user wants to print. This of course does not guarantee that it printed
correctly ie. was not cancelled or the printer chewed up the paper.

--
Hope this helps

Terry Wickenden

Remove access from my E-mail to gain access

RunCommand Constants : http://www.tkwickenden.clara.net/

Tony Toews wrote in message ...

Dimitri Furman

unread,
Mar 24, 2000, 3:00:00 AM3/24/00
to
On Mar 23 2000, 11:47 pm, tto...@telusplanet.net (Tony Toews) wrote
in <rrsldsk9389sqdvun...@4ax.com>:

>Folks
>
>We have a situation where we would like to take some action when a
>report is being printed. The user will preview the report several
>times but when its being printed we want take some action.
>(Actually we're going to email the report as well as print it but
>only when printed..)
>
>However I'm unable to find any method of determining, in code, if
>the report is being previewed or printed. Maybe I'm overlooking the
>obvious. <smile>

Tony,

I believe you might be able to use the Activate event. It fires only
when the report is opened for preview, not for printing. There were
some threads about it on Deja.

--
(remove a 9 to reply by email)

Pete B

unread,
Mar 24, 2000, 3:00:00 AM3/24/00
to
Here's one way (code is copyrighted by the ATTAC Consulting Group, but is
published as freeware on their website as noted. If in doubt, contact
Steve, he visits the NG here now and then, and I think he is in Dev's
webring too.)

How Can I Tell If My Report Was Opened In Preview or Printed?
There are occasions where in your application, you need to know if a report
was printed or previewed in order to allow for some action to be taken
after printing and to not take a similar action (e.g. an update query,) if
the report was only previewed.
To determine this, you can call the following function from your report's
OnClose event. It will return true if the report was previewed, and false
if it was sent to the printer.

If a call to this function returns false, then have your report call a
second subprocedure which sets a module level variable in whatever module
opens the report to act as a flag on whether to take action or not.

The one trick to using this code, is that you should remove the print icons
from both the tool bar and menu for your reports (Do this by creating
custom tool bars and menus) because if the user previews the report and
then prints from the preview, the function will still return a value of
true for the report only being previewed.

(Note this is Access 95/97 syntax, the same api's exist in 16 bit versions
for Access 2, but you would need to change the declares)

Declares:

Private Declare Function GetWindowText _
Lib "user32" Alias "GetWindowTextA" _
(ByVal hWnd&, ByVal lpstrTitleBuff$, _
ByVal intCharstoCopy%) as Long
Private Declare Function GetClassName _
Lib "user32" Alias "GetClassNameA" _
(ByVal hWnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function GetWindow _
Lib "user32" (ByVal hWnd As Long, _
ByVal wFlag As Long) As Long
Private Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" _
(ByVal hwndParent As Long, ByVal hWndChid As Long, _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function IsWindowVisible Lib _
"user32" (ByVal hWndTarget As Long) As Long


Public Function ChkPreview(RptName As String) As Boolean
'-------------------------------------------------------
'Purpose: To see if an Access report is open in preview
'or not (i.e. its opened to print)
'Accepts: Report Name up to 100 characters
'Return: True if in preview, false if not
'Copyright © 1997-98 ATTAC Consulting Group, Ann Arbor, MI USA
'All rights reserved.
'---------------------------------------------------------
On Error GoTo Err_MWC
Dim Winhwnd&, hWndMIDI&, hWndTarget&
Dim ClsNameBuff$
Dim ClsBuffsz%
Dim TitleBuff As String * 100
Dim titlestr$
Dim dwReturn&

Const TARGET_WINDOW_MIDI = "MDIClient"
Const TARGET_WINDOW_DB = "OReport"
Const GW_HWNDNEXT = 2
Const GW_CHILD = 5

ClsBuffsz = 30
ClsNameBuff = Space(ClsBuffsz)

ChkPreview = False
Winhwnd = Application.hWndAccessApp
hWndMIDI = FindWindowEx(Winhwnd, 0&, TARGET_WINDOW_MIDI, vbNullString)
If hWndMIDI = 0 Then
'If its not found exit gracefully
Exit Function
End If
'Found the MIDI Client Class, Now find the OReport Class window
'by looking through children for a report with the like name.

hWndTarget = GetWindow(hWndMIDI, GW_CHILD)

While hWndTarget > 0
dwReturn = GetClassName(hWndTarget, ClsNameBuff, ClsBuffsz)
If InStr(ClsNameBuff, TARGET_WINDOW_DB) > 0 Then
dwReturn = GetWindowText(hWndTarget, TitleBuff, 100)
titlestr = Trim(TitleBuff)
If InStr(titlestr, RptName) > 0 Then
dwReturn = IsWindowVisible(hWndTarget)
If dwReturn = 1 Then ChkPreview = True
Exit Function
End If
End If
hWndTarget = GetWindow(hWndTarget, GW_HWNDNEXT)
Wend

Exit_MWC:
Exit Function
Err_MWC:
Resume Exit_MWC
End Function

*************

If that one is not to your fancy (personally, I think it tends to be
overkill), here's another way, from the old Access Dev web site that went
out of business a while back (what a shame, that). Note the reference to
the MSKB article as well. This one is also PD as were all the code
routines posted there when it was in business. I think Mr. Frenkel is
author.


Detecting Print from Preview

Vadim Frenkel, Xenergy, Inc. of Burlington, Massachusetts USA.
------------------------------------------------------------------------


RE: Print Preview Mode vs. Print Mode: Which One Did the User Open the
Report With? by Mike Divis.

How would I determine, in the code associated with a Report, whether the
user opened the Report in Print Preview mode vs. in Print mode?

Use report Activate and Deactivate events to detect Preview Mode.
Activate/Deactivate doesn't happend in Print Mode.

There 's also way to detect Print from Preview. MS Knowledge Base article
Q154894 describes it, but example there is wrong! Here is my version:


Dim Printing As Integer
' Use global if you want to test from subreport

Private Sub Report_Activate()
Printing = -1
End Sub

Private Sub Report_Deactivate()
Printing = 0
End Sub

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
Printing = Printing + 1
End Sub

Private Sub Report_Close()

If Printing >= 1 Then
' This only works if report was printed, including print from preview!

End If

End Sub
****************

I have tested both methods, both work equally well IMHO. But I do not
actually use them, as I think it is easier to just control when the printer
is available to the user via custom menus.

--
Pete B

Tony Toews <tto...@telusplanet.net> wrote in message
news:rrsldsk9389sqdvun...@4ax.com...


> Folks
>
> We have a situation where we would like to take some action when a report
is being
> printed. The user will preview the report several times but when its
being printed
> we want take some action. (Actually we're going to email the report as
well as print
> it but only when printed..)
>
> However I'm unable to find any method of determining, in code, if the
report is being
> previewed or printed. Maybe I'm overlooking the obvious. <smile>
>

0 new messages