Fire On Close event based on Report state (1 Viewer)

SkyCraw

Registered User.
Local time
Today, 01:02
Joined
Oct 9, 2013
Messages
100
Hello everyone,

Is there any way to decipher between outputting a report and opening a report in VBA?

I have code within a report's On Close event that I only want run when the report is opened in Print Preview. I've tried using the following...

Code:
Reports(rptname).CurrentView

OR

Me.CurrentView

... but I get the same value returned whether I open the report in Print Preview mode or when outputting it.

Thanks in advance for any assistance :)
 

bob fitz

AWF VIP
Local time
Today, 05:02
Joined
May 23, 2011
Messages
4,721
If you put the following line of code:
Code:
MsgBox "report closed"
in the reports On Close event does the message box show when the report is sent to a printer or just when the report closes after being opened in preview mode.
 

SkyCraw

Registered User.
Local time
Today, 01:02
Joined
Oct 9, 2013
Messages
100
If you put the following line of code:
Code:
MsgBox "report closed"
in the reports On Close event does the message box show when the report is sent to a printer or just when the report closes after being opened in preview mode.

Thanks for the reply Bob!

It appears both times when I try using just a msgbox in the On Close event after opening it using either one of the following methods:

Code:
DoCmd.OpenReport rptname, acViewPreview
DoCmd.OutputTo acOutputReport, rptname, acFormatPDF, filepath, False
 

bob fitz

AWF VIP
Local time
Today, 05:02
Joined
May 23, 2011
Messages
4,721
From your first post:
I have code within a report's On Close event that I only want run when the report is opened in Print Preview.
Why not run the required code after the line of code that opens the report in preview mode
 

SkyCraw

Registered User.
Local time
Today, 01:02
Joined
Oct 9, 2013
Messages
100
From your first post:
Why not run the required code after the line of code that opens the report in preview mode

Right now, it's to hide the Access window and just display the pop up search and input forms I have once the report is closed. I have all my menus and input forms as pop ups, but search forms and reports appear within the Access window.

Reason why this is a problem is hiding Access seems to affect how my automated emails are displayed using the Outlook.Application object (even when I use the .display parameter with the Outlook.MailItem object).

Edit:

Is there a way to delete the "On Close" event of a report in VBA? I discovered (after thinking your answer over) using CreateEventProc on the button that opens my report in Print Preview will get me where I want, now I only need to either...

  • Check for the On Close event of the report prior to re-creating it
  • Delete and re-create the On Close event
 
Last edited:

Users who are viewing this thread

Top Bottom