Printed?

geralf

Registered User.
Local time
Today, 18:53
Joined
Nov 15, 2002
Messages
212
I have a report which the user can preview. If he sends it to the printer, is there some way I can know that it has been sent to the printer/print manager ? I need tohave a timestamp when the report was printed, not only previewed. Is this possible?

Thanks in advance
 
from microsoft,it works fine

Create a table with the following structure:

Table: tblPrintedReports
--------------------------------------------------
Field Name: ID
DataType: AutoNumber
Indexed: Yes (No Duplicates)
Field Name: ReportName
DataType: Text
FieldSize: 75
Field Name: PrintDate
DataType: Date/Time
Format: General Date

Table Properties: tblPrintedReports
-----------------------------------
PrimaryKey: ID

Create a new module and type the following lines in the Declarations section:

Code:
      Option Explicit
      Global Flag

Save the module as basPrintedReports, and then close it.
Create an AutoReport based on the Customers table. Save the report as rptCustomers.
Open the rptCustomers report in Design view. Set the report's OnActivate property to the following event procedure:

Code:
      Private Sub Report_Activate()
      Flag = 0
      End Sub

Set the report's OnDeactivate property to the following event procedure:

Code:
      Private Sub Report_Deactivate()
      Flag = -1
      End Sub

Set the report header's OnPrint property to the following event procedure.

NOTE: You must include the report header section on the report, and its Height property must be greater than zero. However, you do not have to place any controls in the header section.

Code:
      Sub ReportHeader3_Print (Cancel As Integer, PrintCount As Integer)
      Dim dbs As Database, rst As Recordset
         Set dbs = CurrentDB()
         Set rst = dbs.OpenRecordset("tblPrintedReports")
      Flag = Flag + 1
      ' If the current value of Flag = 1, then a hard copy of the
      ' report is printing, so add a new record to the history table.
      If Flag = 1 Then
         rst.AddNew
         rst!ReportName = "rptCustomers"
         rst!PrintDate = Now
         rst.Update
         Flag = 0
      End If
      End Sub

Save the rptCustomers report, and then close it.
Generating a History Record


Select the rptCustomers report in the Database window.
On the File menu, click Print to print the report.
Open the tblPrintedReports table. Note that a new record shows the report name, and the date and time it was printed. For example:

ID ReportName PrintDate
--------------------------------------
1 rptCustomers 09/05/04 3:25:11 PM
 
Hi biskra, and thank you for your answer. I've been away a couple of days, hence the late reply.

I have not tried it out yet, but as I understand from the posted code, it's the reports aeactivate and deactivate that is truggered when the report prints. I presume here that you must send the report directly to the printer. I would guess that if it was previewed the same events would be triggered. A report preview can be canceled without being printed. I can probably avoid the preview, since the report is based on a form which have the same information.

Could you post the link to Microsoft where you found this?

TIA and thank you for your help!
 
REFERENCES
For more information about Activate and Deactivate events, search the Help Index for "Activate," or ask the Microsoft Access 97 Office Assistant.

For more information about Print events, search the Help Index for "Print Event," or ask the Microsoft Access 97 Office Assistant.
The information in this article applies to:
Microsoft Access 2.0
Microsoft Access for Windows 95 7.0
Microsoft Access 97
Last Reviewed: 5/9/2003 (2.0)
Keywords: kbhowto KB154894
 
I tried to create a print history using the code provided, but I wasn't successful.

Attached please find the database.

It has to be something simple.

Any help would be appreciated.
 

Attachments

The example above from microsoft works except that the print event code is slightly wrong. It should be

Code:
  Sub ReportHeader3_Print (Cancel As Integer, PrintCount As Integer)
      Dim dbs As Database, rst As Recordset
         Set dbs = CurrentDB()
         Set rst = dbs.OpenRecordset("tblPrintedReports")
     
      ' If the current value of Flag = 1, then a hard copy of the
      ' report is printing, so add a new record to the history table.
      If Flag = 1 Then
         rst.AddNew
         rst!ReportName = "rptCustomers"
         rst!PrintDate = Now
         rst.Update
         Flag = 0
      Else
         Flag = Flag + 1      
      End If
      End Sub


HTH,

Tom
 

Users who are viewing this thread

Back
Top Bottom