VBA detect if in preview or printing

GTA_doum

New member
Local time
Yesterday, 22:50
Joined
Feb 11, 2011
Messages
6
Hello,
Is there any way to detect from VBA Format event code, that the report is currently in preview or actually printing to the printer?
Thanks,
Dominic
 
Confused.

The act of "printing" from an application's point of view is really very quick.
The print job goes to a Printer buffer and is actually printed from that buffer.
Detecting if that buffer is still printing would seem to demand communicting with windows and or the printer's driver.

Detecting if Access has the Print Preview pane active, is not necessarily connected to the physical act of printing, unless your project's code has made it so.

Can you elaborate more on your scenario?
 
You don’t say what version you are using but in Access 2003…

If the Report is going to screen then the Report’s Report_Activate() event will fire else it won’t.

The Report_Activate() event fires before the Detail_Format event.

Chris.
 
Hello,
I am using Access 2010. The report is always in preview mode first. The Detail_Format event of a section will fire up if that section is viewed (my report contains sub-reports). If we are viewing page 1, and not going through all pages, some print events will not be called. If we start a print, then all pages will be gone through, and all events programmed will be called.

I would like to know when the event is called, is it from the preview window, or from the print routine of Access...
 
>>I would like to know when the event is called, is it from the preview window, or from the print routine of Access...<<

Which event; the Detail_Format event or the Detail_Print event?

In Access 2003 it appears that the Detail_Format event it called for all Pages but the Detail_Print event is only called for the Page(s) which are displayed.

Try this to test:-
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    Static X As Long
    
    If X <> Me.Page Then
        MsgBox "Print  " & Me.Page
        X = Me.Page
    End If

End Sub


Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Static X As Long
    
    If X <> Me.Page Then
        MsgBox "Format  " & Me.Page
        X = Me.Page
    End If
    
End Sub

You may also need to tell us why you want to know that because some things in Reports can’t be done after formatting or printing has started.

Edit:
And I would not guarantee that order of events only happening once. It may be for a large Report, which can’t be held entirely in memory, that some of the events may double up.

Chris.
 
Last edited:
Hello,
I tried from the Format and Print event, and from both, I can modify a control before it shows (render)! I taught that it needed to be done from the Format event. In fact, using the Print event, which is called only before rendering the page, resolves another issue I had, that my procedure was called too often.

Now, let's say I'm viewing to the screen the report, browsing through the pages, then printing the report. Let's say also that the Print event is trapped on a sub-report appearing only on page 6.
When previewing that page, the Print event is called, only once, even if I look at another page, then return to page 6.
I then print the report, the Print event is called again for that page.
It's perfect for my routine, but I would like my routine to know for which it is executing!

My routine renders the first page of a PDF on the Access report, in an image field. If it is viewed on the screen, the render is only at 72dpi, which is fine for the screen, and fast. If it prints, I want it to render to what the printer is capable, but it is much slower!
 
Sounds a bit complicated to me.

How about two buttons that activate the Report? One button opens the Report in preview mode on screen and the other prints the Report. The print button could have a confirm facility so they don’t accidentally try to print it.

The two buttons can then pass a print mode flag through OpenArgs.

Chris
 
I do not understand what is complicated! If the procedure knows what's calling, then my problem is resolved!
So is there a way to know? Is there some call or a special property somewhere to know which of the two is rendering the report page?
If there is, then it is simple, if not, then yes, the way to know will be complicated! But I am ready to work on this, I just need a headstart! Even if I need to call a Windows special DLL function, I'll do it... Like the day I wanted to know the real IP, from VBA, of the PC connecting through RDP. It was complicated but I found some code, took a day at it, and it was working, while watching the olympics on TV few years back :).
 
If I knew how to do it directly in code from the Report I would have told you.

I don’t know how to do it like that so I gave you a workaround; one button for low resolution to screen and the other for high resolution to printer.

If you are activating the Report from Form buttons then it is easy. If you are activating the Report from the ribbon then it might be more complicated.

But I don’t know how to do it directly in code from the Report so if someone else does then go for it.

Chris.
 

Users who are viewing this thread

Back
Top Bottom