ReportHeader_print problems

Hi All,
Ive written a bit of code which prints out a word doc (a title page), i thought if i placed the code in the reportHeader_print() event it would be fine (i cant seem to find a Report_print event). the problem im having is that my title page keeps printing when i click on the print preview button when all i want is the title page to be printed when the actual report is printed! how do i do that please!

Amarino
AmarinoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

puppydogbuddyCommented:
Rather than issue a print command from within the report, why don't you just place your code after you print the report like this:

DoCmd.OpenReport "YourReport", acViewNormal
Your code to load and print the document
harfangCommented:
Hello,

I must admit I'm very annoyed (with MS and/or myself). I could find no way, official or a hack, to determine whether the current printing is a preview or an actual printing... Viewed from Access or from the report object, everything is exactly the same in both cases...

You can of course provide buttons, e.g. "print with title page", from your interface, but when the users chooses "preview" and then decides to print, you can only hack into the interface:

 * Create a custom menu, a custom toolbar, and a custom shortcut menu
 * Link those to your report(s)
 * Reprogram the buttons and menu items "print" to run your own code

It would be soooooo much simpler if Access had exposed this item of information:

    If Me.CurrentView = acReportNormal Then MyPrintTitleFunction(Me)

I'll look a little more, but I already checked all the obvious places...

(°v°)
harfangCommented:
Ah, here we go.

I found a newsgroup thread about that problem. The hack, suggested by MS, is to use the Activate event. This occurs only when previewing the report (when the window is created and activated). What's more the report header, on page one, will get printed each time. So we can distinguish these:

 * Activate - Print   = preview
 * Activate - Print - Print   = printing from preview
 * Print   = direct printing.

References: http://support.microsoft.com/kb/q154894/
(note: the example is buggy and doesn't detect printing from preview)
http://groups.google.com/group/comp.databases.ms-access/browse_thread/thread/654e662854ea278b/d14c8b12db5c5349%23d14c8b12db5c5349

In a small test report, I used this module:

-----------------------------------------------------------------------------------------------
Option Explicit

Dim gintState As Integer

Private Sub Report_Activate()
    gintState = -1
End Sub

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
    If PrintCount = 1 Then gintState = gintState + 1
    If gintState > 0 Then
        MsgBox Me.Name & " is being sent to printer!"
    End If
End Sub
-----------------------------------------------------------------------------------------------

And that does work.

Good luck!
(°v°)

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
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

AmarinoAuthor Commented:
Thanks a lot for your help harfang! that helps me out a lot! i was thinking along the same lines my self but i didnt know about report_active event. i used your code and it stopped the title sheet from printing out in print preview but when i finally decide to print out the report, the title sheet gets printed out three times! havent had time to step through the code yet to see why.  Any ideas?

The sub i used to print the doc is given below. (also found using this sites help)

Sub PrintTitleDoc()
   Dim WordObj As Object
   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open CurrentProject.Path & "\FRONT.doc"
   WordObj.PrintOut Background:=True
   WordObj.Documents.Close SaveChanges:=0
   WordObj.Quit
   Set WordObj = Nothing
End Sub

and the code i used in the reportheader_print() event is as follows


Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
    If PrintCount = 1 Then gintState = gintState + 1
    If gintState > 0 Then
        Methods.PrintDoc
    End If
End Sub
harfangCommented:
The only idea is that the header is printed several times as well. I tested only with MsgBox...

You should insert a msgbox or a Debug.Print message and check out how and when these three printings occur. As far as I know, you have a parameters that requests three copies ;)
[You call Methods.PrintDoc, but show the definition of PrintTitleDoc(), so I can't tell...]

Good luck with your debugging, tell me how it goes.
(°v°)
AmarinoAuthor Commented:
sorry printDoc should be printTitleDoc...
ill have a play and see if i can sort it out...
thanks again for your help

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.