Counting Command Button Clicks

elgoober

Registered User.
Local time
Today, 06:30
Joined
Mar 2, 2001
Messages
83
I have a command button Cmd1 that every time someone clicks - I need to count the click and store the value - so the first time they click - the value is 1 - next time 2 etc.
Going slightly mad trying

Any help greatly app.
 
hi goober
wink.gif



if you only need the value for the life of the form then
Code:
    Static freddie As Integer
    
    freddie = freddie + 1
    MsgBox freddie

will do it if placed in the onclick event of the button, is this all you need or does it need to be stored in the db for later?

HTH

Drew
 
Not to sure by what life of form means - although having reread my post - not to sure what I meant. Should be when user clicks button - Cmd1 - report is generated - the count of the onclick (freddie??) needs to go in the report header. So I have a text box say text1 whose control source is - Im really not to sure (is this freddie?)

Again big thanks and sorry for poor explaination
 
okay, we'll lose freddie
frown.gif
, he's a bad habit of mine along with bob boolean and dave double. Okay, so a new report is going to open, in that case probably disregard the above and in a module somewhere put Public intSensiblyNamedInteger as Integer (
wink.gif
), on the OnClick event you'll then want
intSensiblyNamedInteger=intSensiblyNamedInteger + 1
docmd.openreport "ReportName",acViewPreview

and on the OnPrint of the report section that contains your text1 you need
Text1.Value = intSensiblyNamedInteger


HTH

by life of the report i meant from when it's opened to when it's closed, after that the static would return to 0

Drew
 
Drew

Done all of the above - but when you click cmd button it moves thru criteria - typing date periods - flashes very quickly then disappears - tried acView Normal but got a 3015 error message - telling me not to click cancel - which I had not

This feels close but...
copy of code used
Private Sub Command35_Click()
Dim intPrintcalcInt As Integer
intPrintcalcInt = intPrintcalcInt + 1
DoCmd.OpenReport "Query2", acViewPreview


End Sub
 
You do need to make intPrintcalcInt publicly available rather than just within the button code, put Public intPrintcalcInt as Integer in a Module, a new one if u don't have any.

Just to make sure - Query2 is a report and not a query? Do you have some other code placed on this command button? There's nothing above that would move you through any date periods, or anything else. What's flashing when u click it? Is there any code on the report open event that would cause the report to cancel opening under certain conditions?

Drew
 
Drew

I tried the public one once and failed - but in between went back and lo it all works

What can I say

Big thanks

Paul
 
Drew
Not too sure if you will see this but anyways the code works fine but... every time user goes out of db and then back in - the report numbers reset to 0 - and also the db is on a network and if a user on a different machine presses button - no starts at 0. I need the number to be continually updated to allow audit trail.

Any suggestions?

Agains regards for your help

Paul
 
Because the variable is Public it is created and shared between all the db's object. But only for the life of the DB session.

If you want to continually increment a value you will have to set up a one field table to hold the value and save it there every time the user updates an invoice, then when the user clicks to print an invoice increment it by running an update query.

Remember though that if you use this method, if the users prints the same invoice twice it will have two different invoice no's. That is why it is best to have a field in your table which will retain the invoice number on your behalf. You could call it InvNo and set it to long integer. Now when the user clicks the button you should check to see if the InvNo field has a value and if not assign the next InvNo to it.

I know it's a bit complicated but without using an autonumber as the invoice number you are destined to have to manipulate the system to create your unique references.

Ian
 
Add a field to a table named MyNumber and then put a control on the form with that field as its source. Then do something like this:

Private Sub cmdIncrementNumber_Click()

MyNumber = MyNumber + 1

End Sub

This will store the number in the table at increment it by one everytime it is clicked. And because it is in a table the number will not be restarted every time the database is.

I am not sure what happens when two users increment it at the same time though so you may want to do some experimenting with it before you put it into production.
 

Users who are viewing this thread

Back
Top Bottom