Want to count entries in form (1 Viewer)

nashfaq

Registered User.
Local time
Tomorrow, 01:18
Joined
Oct 17, 2018
Messages
28
Hello team

i am Nasir Ashfaq, new here and new in programming in access

i need a small support from you....

i have a form, and want to count how many times New form button pressed.
also need to reset that count when i press reset button.

idea is that i want only 25 entries with one CODE Number, that will make easy when i get my report print so with one CODE i have 25 entries on page.
after 25 entries i will change CODE Number and reset the counter.

regards
Nasir
 

JHB

Have been here a while
Local time
Today, 22:18
Joined
Jun 17, 2012
Messages
7,732
I would suggest a query instead, (a query that count the amount of a special code).
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:18
Joined
May 7, 2009
Messages
19,169
on the Click Event of the button, make the count:

Dim intPressCount As Integer

Private Sub yourButtonToCount_Click()
intPressCount = intPressCount + 1
End Sub

Private sub buttonReset_Click()
intPressCount=0
End Sub

====
what is your code on adding New Record?

docmd.GoToRecord,,acNewRec

you can test intPressCount variable if it is over 25 before adding New Record.
 

nashfaq

Registered User.
Local time
Tomorrow, 01:18
Joined
Oct 17, 2018
Messages
28
Hello

Thanks for support

I also need to display that count in a text box.

Also need reset when I close the form.

Regards
Nasir
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:18
Joined
May 7, 2009
Messages
19,169
Private Sub yourButtonToCount_Click()
intPressCount = intPressCount + 1
Me.UnboundTextbox = intPressCount
End Sub

when you close the form intPressCount is destroyed.
 

nashfaq

Registered User.
Local time
Tomorrow, 01:18
Joined
Oct 17, 2018
Messages
28
Hello

Friend it only shows 1.
When I am pressing again.

Number is not changing...

What wrote in my code is as below
Private sub cmdnew_click()
Dim intpresscount as integer

Docmd.runmacro "newrecord"
Intpresscount =intpresscount +1
Me. Countbox= intpresscount
Endsub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:18
Joined
May 7, 2009
Messages
19,169
put intPressCount outside the Sub:

Option Compare Database
Option Explicit

Dim intPressCount As Integer

Private sub cmdnew_click()
If intPressCount < 26 Then
Intpresscount =intpresscount +1
Me. Countbox= intpresscount

Docmd.runmacro "newrecord"
Else
Msgbox "You are only allowed to have 25 New records"
End If
End sub
 

nashfaq

Registered User.
Local time
Tomorrow, 01:18
Joined
Oct 17, 2018
Messages
28
Perfect...
Thanks for support

its really nice to learn from you.

regards
Nasir
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:18
Joined
May 7, 2009
Messages
19,169
youre welome!
 

Users who are viewing this thread

Top Bottom