Report events not being triggered

Question by:  Pelegrinus On 2012-08-07 01:24 PM https://www.experts-exchange.com/questions/27820593/Opening-an-Access-Report-in-acViewNormal-Doesn't-Trigger-Report-Events.html
I hope this is enough information to let you know the question I am responding to. What I stumbled on is that if a global variable is used within the on open procedure the code will execute even when a report is printed. In a module I placed the following code:
global gbdone as boolean
then inside the on open procedure I placed the the following code, along with the other code I wanted to execute:
gbdone = false
and every thing executes

Thanks for making all this information available to us. (Microsoft sure is not much help most of the time.)
kingsbishopAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick67Commented:
That's interesting and I'll have to check out its implications.
The original was here
http://www.experts-exchange.com/Database/MS_Access/Q_27820593.html
It's not that the Report_Open code doesn't function at all, but breakpoints definitely don't work, and attempts to set .Caption fail -- and since .Caption is the name given to the job in the print queue, and the default name given to the PDF file -- being able to set .Caption successfully is pretty damn important!

I have done that by opening with DoCmd.OpenReport stDocName, acViewPreview and, with the Report open, then printing it out -- but it is more time-consuming than a straight DoCmd.OpenReport stDocName, acNormal to do it that way.

Interesting!
0
Jeffrey CoachmanMIS LiasonCommented:
FWIW....

This thread may be a bit misleading...

Setting the Global variable does noting to force "Formatting" code to work.
ex:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Junk <> "Bob" Then
    Me.Junk.BackColor = vbRed
Else
    Me.Junk.BackColor = vbWhite
End If
End Sub

What I mean is, ...
The title of this question, and the question it references, ...makes it seem like like you have created a workaround for forcing any code to run in Report View.

Just FYI...
0
Nick67Commented:
Agreed.  This has only to do with what happens to the Open() event code when a report is sent directly to the printer via DoCmd.OpenReport stDocName, acNormal

global variable is used within the on open procedure the code will execute

But that's been a problem for a long time, if you change record sources via OpenArgs, or set dynamic captions so that PDF rendering gets a unique filename, that you had to open in Preview and then set off printing.

Touch a global variable in Open() and the full Open() event code executes regardless of how the report was opened.

And THAT is very nice to know -- because the print queue job names are also defaulted to the .Caption.
So it is very sweet to finally be able to get unique names to such in things in all situations.

I have a report without a caption named rptScratchSheet.
I can put this code in the Report_Open(Cancel as Integer) event
Private Sub Report_Open(Cancel As Integer)
Me.Caption = Forms!frmTravellers!JobID.Column(1) & " Scratch Sheet"
End Sub

Open in new window


But if I print it (or export to PDF) via DoCmd.OpenReport stDocName, acNormal
The caption is not set and the print queue job name and PDF default filename remain rptScratchSheet

This code, when myDummy is a global variable in a standard module
Private Sub Report_Open(Cancel As Integer)
MyDummy = False
Me.Caption = Forms!frmTravellers!JobID.Column(1) & " Scratch Sheet"
End Sub

Open in new window

Does cause the .Caption to be set.

Very nice discovery!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
Yes,
Very interesting...
0
Nick67Commented:
Close it with zero points.
It wasn't a Q per se, but there is content here worth preserving

Nick67
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.