Results 1 to 5 of 5
  1. #1
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Reports Print event (Any version)

    The Print event of a report section occurs whether the report is actually printed, or just viewed in Print Preview.

    Is it possible to tell in code whether the report is actually being printed, as distinct from Previewed.

    I would like to put some code in an Invoice that records date printed . I thought it would be neat to let the report handle this itself, rather than having to do it myself.

    I allow users to Preview an Invoice, then decide whether to print once they are in Preview mode.

    Edited later

    Having played around with this, I realise I need to provide more info. My invoices are set up as a report, with grouping by invoice number, Each invoice starts on a new page.
    so I need to know not just whether the report has printed, but exactly whether a particular page has printed.

    I might preview the report showing 10 unprinted invoices availabe, but only choose to print page 5 of these.


    I found an example here in the knowledge base but it only relates to the whole report. I have tried to modify it without success.
    Regards
    John



  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Reports Print event (Any version)

    I have found something that seems to work, by building on the MSKB article I referred to before.

    1: In the report module, define an integer variable: dim Flag as Integer

    2: In the Activate event for the report set Flag =0

    3 Put a hidden textbox in the InvoiceNumber header with its control source =1, and its running sum property to "over group" so that it numbers the Invoices being previewed.

    4 In the Print event of the Invoice Number header: increment the flag (flag = flag +1) then compare the flag with the hidden textbox. While previewing the two will be the same , but if you subsequently print the flag will be larger. This can then trigger the recording of the Printing of the Invoice.

    Any code that Prints the invoice without previewing will need to manage the recording of the printing itself.
    Regards
    John



  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Reports Print event (Any version)

    <P ID="edit" class=small>(Edited by patt on 28-Jul-04 20:27. Added Access 2002 help)</P>I have the following code in a PO print report. It writes a record whether in preview or print. I am using Access 2002, this is to be used for a Client which uses Access 2000.
    I have looked at the Help for the Activate event and it contradicts what the MSKB article says, viz:
    Activate Event
    See Also Applies To Example Specifics
    The Activate event occurs when a form or report receives the focus and becomes the active window.



    Can you see anything wrong, I believe that I have followed the MSKB article correctly.

    The code is:
    <pre>Option Compare Database
    Option Explicit


    Private Sub Report_Activate()
    flag = 0
    End Sub

    Private Sub Report_Deactivate()
    flag = -1
    End Sub

    Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)

    Dim dbs As DAO.Database, rs As DAO.Recordset
    Set dbs = CurrentDb
    Set rs = dbs.OpenRecordset("Audit Prints PO POA MPO")
    flag = flag + 1
    If flag = 1 Then
    rs.AddNew
    rs!UserName = GetUserName()
    rs!DateEditted = Now()
    rs!PrintIdentifier = "PO"
    rs![PO ID] = [PO ID]
    rs.Update
    flag = 0
    End If
    Set rs = Nothing
    Set dbs = Nothing

    End Sub
    </pre>


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reports Print event (Any version)

    The code in the MSKB article is incorrect, they mixed up the Activate and Deactivate code. It should be like this:

    Private Sub Report_Activate()
    flag = -1
    End Sub

    Private Sub Report_Deactivate()
    flag = 0
    End Sub

    If the report is previewed, the On Activate event of the report sets flag to -1, then the On Print event of the header increases it to 0. So the test fails, and no log record is added. If the user then prints, the On Print event of the header occurs again, and flag is increased to 1. The test succeeds, and a log record is added.
    If the report is printed directly without previewing, the flag is 0 initially, and increased to 1 by the On Print event of the report header, so a log record is added.

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Reports Print event (Any version)

    Thanks Hans, I was experimenting with the different values after I noticed you were looking at an old post, but I was then testing it to 0 rather than one as you found out.
    Thanks again mate, that will keep the client very happy indeed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •