[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

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
0
Amarino
Asked:
Amarino
  • 3
  • 2
1 Solution
 
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
0
 
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°)
0
 
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°)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
0
 
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°)
0
 
AmarinoAuthor Commented:
sorry printDoc should be printTitleDoc...
ill have a play and see if i can sort it out...
thanks again for your help

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now