Is Report actually printed?

  • Thread starter Thread starter JerryC
  • Start date Start date
J

JerryC

I have a date field in a table called "PMPrinted"

Using VBA code:
When someone Previews a report and they click the Printer
Icon I want to put todays date into the PMPrinted field
of the record or records printed.
If they only Preview and not print I want to leave the
PMPrinted field null.

Thanks in advance for any ideas on this.
 
I have a date field in a table called "PMPrinted"

Using VBA code:
When someone Previews a report and they click the Printer
Icon I want to put todays date into the PMPrinted field
of the record or records printed.
If they only Preview and not print I want to leave the
PMPrinted field null.

Thanks in advance for any ideas on this.

The below code will add the date you sent the report to the printer to
your table field PMPrinted.

However, the fact that you sent the report to the printer does NOT
guarantee that the report was in fact successfully printed.
Printers do run out of paper, ink, and sometimes just pass away
quietly in the night.

NOTE: The correct code depends upon whether or not you have a control
in the report compuing [Pages], i.e. Page 1 of 4.
Select the correct lines.

Note that intPreview is Dimmed up in the codes Declaration section.

Option Compare Database
Option Explicit
Dim intPreview As Integer
===========

Private Sub Report_Activate()
intPreview = -2 ' with [Pages]
' intPreview = -1 ' without pages
End Sub
==============

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As
Integer)

If intPreview >= 1 Then ' with [Pages]
'If intPreview >= 0 Then ' without [Pages]

' Append a new record to the table with the current date if printed
CurrentDb.Execute "Insert into tblData (PrintDate) Values (#" & Date &
"#);", dbFailOnError

End If
intPreview = intPreview + 1

End Sub
=======

I have used an Append query to add a new record with the current date
to your table.

You can, instead, use an Update query to change the value in a
particular EXISTING record. In this case you need to be able to add a
where clause to the query to update just the one record.

CurrentDb.Execute "Update YourTable Set YourTable.PMPrinted = #" &
Date & "# Where ADD YOUR CRITERIA HERE;" , dbFailOnError
See VBA help on
Where clasue + restrict data to a subset of records
 
Back
Top