On_Print

  • Thread starter Thread starter David
  • Start date Start date
D

David

I would like to run some code when a report is printed to modify a field in
a table so I know the invoice was printed.

How can I accomplish running code on print?

Thanks,

Dave
 
There is not a simple, generic way to do what you asked.

If you have a command button on your form, and it prints the current record
like this:
DoCmd.OpenReport "rptInvoice", acViewNormal, , "InvoiceID = " &
Me.InvoiceID
then you could just add another line that sets the value of the field to
record when it printed.

However, there are so many things that can go wrong with this process, that
the approach is deeply flawed, e.g.:
a) It may not have printed (e.g. printer off, out of ink, network broken,
paper jammed.)

b) It may have been printed from another interface (other than that button
on your form.)

c) Unless you rebuild the entire interface, using custom toolbars, menu,
shortcut menus, etc, there is no way to detect whether a record was printed
or just previewed.

d) You can try to detect what filter was applied to the report to know which
records might have printed, but the Filter property may be an artifact.
Access does not maintain the report's FilterOn property reliably.

e) If something did go wrong, and you just recorded a yes/no (printed or
not), there is no way to know which value(s) you just set, so there is no
way to undo that process.

In a database where the user cannot get to the database window, you can
generate a log of which records were printed, by whom, when, and in what
batches. That does allow you to track them correctly, and to rollback (undo
a batch) or reprint (send the same batch again) if a print operation is not
successful. This requires a separate logging table, a batch table, and some
coding skills to execute an Append query to record the key values of the
values that were printed in the batch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top