UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> How To Keep Track Print Button Clicks, Office 2007    
 
   
edwintdc
post Feb 27 2012, 12:18 AM
Post #1

New Member
Posts: 13



Hi UA,

I need to keep track of the number of reports (a counter) that gets printed from my application. The count will be saved in a table that gets incremented every time the print button is clicked. The problem is how do I know that the print button has been clicked. Is there a VBA code that traps print button clicks. I'm on Access 2007. Any help would be greatly appreciated.
Go to the top of the page
 
+
polant
post Feb 27 2012, 12:34 AM
Post #2

UtterAccess Guru
Posts: 583
From: Cyprus



Hi

You already have the button that prints a report, so you need to add to the code behind it so that it increments the value in the table. As usual, there are more than one ways to go about:

1. Run an update query to increment the counter
2. Create a recordset from the table and increment the counter by:
rst.Edit
rst!PrintCounter = rst!PrintCounter + 1
rst.Update

The easiest way would be to have the form (on which the button is located) bound to the table and have a (hidden) textbox bound to the counter field. You would use the following code:
Me.PrintCounter = Me.PrintCounter + 1
Me.Dirty = False

Hope this helps.
Go to the top of the page
 
+
edwintdc
post Feb 27 2012, 09:50 AM
Post #3

New Member
Posts: 13



I've got a button in a form that when clicked, displays the report (actually an invoice) in "print preview" mode. At print preview, the report can be printed through the print icon on the Ribbon. Adding the report counter's code to the button in the form is not what I want - the user may change his/her mind and not print the report. In this case, the counter should not be incremented. The counter should be incremented only once the user clicks the print icon on the Ribbon, and the report printed. How do I keep track the print event on the Ribbon?
Go to the top of the page
 
+
polant
post Feb 27 2012, 01:26 PM
Post #4

UtterAccess Guru
Posts: 583
From: Cyprus



Hi

This complicates things. The answer is that I don't know. I never faced a similar situation.

However I experimented a bit with report events and I have something that might work.

I noticed that the report Open event does not fire when you print the report if that is already opened in print preview. On the other hand, a section's Print event fires every time. So using the above and a module wide variable I think I can 'identify' when a report is actually printed. Please note that you need to use a section that appears only once in the report.

CODE
Option Compare Database
Option Explicit

Dim blnPrintMode As Boolean

Private Sub Report_Open(Cancel As Integer)
blnPrintMode = False
End Sub

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
If blnPrintMode Then
    'Code to increment stored counter goes here
Else
    blnPrintMode = True
End If
End Sub


This is not really a well tested solution, but it seems to work with a very simple report I used. Perhaps someone else will give us a better solution.
Go to the top of the page
 
+
edwintdc
post Feb 29 2012, 01:11 AM
Post #5

New Member
Posts: 13



Hi Polant,

First of all thank you for taking the time to reply to my post.
I invoke the report with a code like this, "DoCmd.OpenReport "rptReceiptA5", acViewPreview, , , acWindowNormal". The report's 'Open' event gets fired and then the Report Footer's 'Print' event gets executed (I attach the code to the footer section because the header section is empty). Now MS-Access displays the report in 'preview mode'. When I clicked the Print icon on the Ribbon's Print Preview tab, the Print dialog box was displayed but the Report Footer's 'Print' event did not fire and so the code that increments the value in the table did not execute. What's wrong? Am I missing something?
Go to the top of the page
 
+
polant
post Feb 29 2012, 08:11 AM
Post #6

UtterAccess Guru
Posts: 583
From: Cyprus



Hi

I checked it out and you are right. Report Footer Print event does not fire. I don't know why. Report Header Print event on the other hand seems to work perfectly. I would suggest moving the code in there even if the section is empty, and see how it goes.

Anyway I attach the db file I experimented with, seems to work. Double click the report in the navigation pane and it will open in print preview. Then print it. The counter in tblSettings will increment by 1.

Hope this helps.
Attached File(s)
Attached File  Demo.zip ( 27.45K ) Number of downloads: 6
 
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th June 2013 - 12:20 PM