Count the time a button is clicked?

lovelykid23

New member
Local time
Today, 09:38
Joined
Aug 10, 2016
Messages
8
Hi guys,

I have a Form to input data into my table. Sometimes, the data needs to be duplicated exactly so I added a "Duplicate Record" button. I was wondering if there is any way to count the times I click on the Duplicate button (so I know how many times the data was copied)? So like every time I click on the Duplicate button, the data will be duplicated and the number of times I clicked will be counted?

I searched everywhere and couldn't find a way for a button to do both functions at once.
 
Last edited:
Well, you'd need to save the value in a table to have it hold when the database is closed. So, you'd either increment a number in that table or add a new record. Is it by record, or overall?
 
It is by record. And it is ok if next time I open the form, the counting reset from 0.
 
Then you can use a form-level variable and just increment it:

VariableName = VariableName + 1

or a textbox so the user can see it

Me.TextboxName = Me.TextboxName + 1
 
VariableName = VariableName + 1

or a textbox so the user can see it

Me.TextboxName = Me.TextboxName + 1

Where can I add them? Can I do this with macro? Or I have to write a code?
Thanks,
 
1.You can create the target table [hits] in a number format

2.You can add text box on the form naming it [hits] and make it not visible or visible.

3. Your code should look something like this when added to the On Click Event:

Private Sub Command3_Click()
If IsNull(Me!Hits) Then
Me!Hits = 0
Else
Me!Hits = Me!Hits + 1
End If
End Sub
 
Where can I add them? Can I do this with macro? Or I have to write a code?
Thanks,

I don't use macros, but you can probably do it with SetValue or SetProperty, and either change a form control or a TempVar.
 
I’m not sure if you can do precisely what you have requested with macros, but depending on how many duplicates you may need at any one time you may want to do this a different way, which does work with macros. I’m also assuming you do not have all the duplicates open at the same time.

Copy and paste a copy of your form changing the name, possibly by adding duplicate to the end.

Create a Submacro, which I will call Duplicates.
The Submacro should be;
OpenForm
Form Name; Should be the name of your duplicate form
View; Form
Filter and where condition should be left blank
Data Mode; Add
Window Mode; Hidden

Put an unbound control in the original form and in the property sheet data tab for the control set the default value to 1.
In the On Click event of your duplicate button create SetTempVar for each control you want to copy.
In-addition set a SetTempVar for the unbound control, which I will call Count. So the SetTempVar should be “Name” Count – “Expression” [Count]
Then use the RunMacro command to call the submacro you created.
Macro Name; Macroname.Duplicates
Repeat Count; =[TempVars]![Count]
Leave Repeat Expression blank.
After calling the submacro remove the TempVars Count.

In the On Load event of the duplicate form;
SetProperty for each of the TempVars except the Count.
RemoveTempVars for each of the TempVars except the Count so they always get cleared.
RunMenuCommand – SaveRecord
CloseWindow.

Now even if you want as much as 100 duplicates just change the 1 to 100 in the Count box and click the duplicate button and it will duplicate the form 100 times.
It might not be the best way of doing this but it is all in Macros and it does work.
 

Users who are viewing this thread

Back
Top Bottom