Want to count entries in form

nashfaq

Registered User.
Local time
Today, 17:37
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
 
I would suggest a query instead, (a query that count the amount of a special code).
 
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.
 
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
 
Private Sub yourButtonToCount_Click()
intPressCount = intPressCount + 1
Me.UnboundTextbox = intPressCount
End Sub

when you close the form intPressCount is destroyed.
 
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
 
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
 
Perfect...
Thanks for support

its really nice to learn from you.

regards
Nasir
 
youre welome!
 

Users who are viewing this thread

Back
Top Bottom