Counting button presses

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all.

Simple question. I have a button that prints a report. I would like to
have a field on the form where the button is, that has the number of times
the report has been printed.

(I will actually be using this number on the report as a "group number" for
the tickets the reports print.)
 
EH said:
Simple question. I have a button that prints a report. I would like to
have a field on the form where the button is, that has the number of times
the report has been printed.

(I will actually be using this number on the report as a "group number" for
the tickets the reports print.)


Add a (hidden?) text box to the form's header/footer
section. Then the button can use code like:
me.thetextbox = Me.thetextbox + 1
to count the button clicks.

The report can display the value in the text box by using a
text box of its own with an expression like:
=Forms!yourform.thetextbox
 
Ya know..i was just browsing and saw that formula. which is really quite
simple. For some reason I tried it earlier and didnt get it to work, but now
it works fine. Thanks Marshall.
 
How do i get this textbox (named txtGroup) to save the number in case the
user closes the application?

I have set up a separate table (named tblGroup)with just Group as a field.

I have gone through and tried some of the update query SQL commands but I
cant seem to get it to work. Getting detailed with VBA/SQL isnt really a
strong suit of mine.

So I have a form (frmStyle) with a textbox (txtGroup) incrementing +1 on a
click of the button (btnPrint). I need to save the value of (txtGroup) to
(tblGroup) so it comes back up in the field.
 
Not sure where you want to do this, maybe in the form's
Close event?

CurrentDb.Execute "UPDATE tblGroup SET [Group] = " _
& Me.txtGroup

To load that value when the form opens, use the form's Load
event:
Me.txtGroup = DLookup("Group", "tblGroup")

Except, you should not use Group as a field name, it's an
SQL keyword and may cause your SQL statement to be
misinterpreted (change the field name to something else like
GroupPrint). Actually, between SQL, Access and VBA, there
are tons of ordinary words that are "reserved", so the
safest thing to do is never use an English word for anything
you create.
 
awsome! that worked perfectly! Changed the name as you suggested. Thanks a
ton!

EH

Marshall Barton said:
Not sure where you want to do this, maybe in the form's
Close event?

CurrentDb.Execute "UPDATE tblGroup SET [Group] = " _
& Me.txtGroup

To load that value when the form opens, use the form's Load
event:
Me.txtGroup = DLookup("Group", "tblGroup")

Except, you should not use Group as a field name, it's an
SQL keyword and may cause your SQL statement to be
misinterpreted (change the field name to something else like
GroupPrint). Actually, between SQL, Access and VBA, there
are tons of ordinary words that are "reserved", so the
safest thing to do is never use an English word for anything
you create.
--
Marsh
MVP [MS Access]


How do i get this textbox (named txtGroup) to save the number in case the
user closes the application?

I have set up a separate table (named tblGroup)with just Group as a field.

I have gone through and tried some of the update query SQL commands but I
cant seem to get it to work. Getting detailed with VBA/SQL isnt really a
strong suit of mine.

So I have a form (frmStyle) with a textbox (txtGroup) incrementing +1 on a
click of the button (btnPrint). I need to save the value of (txtGroup) to
(tblGroup) so it comes back up in the field.
 
Back
Top