Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count the button clicks + Display the count 1

Status
Not open for further replies.

mchester

Technical User
Jul 1, 2005
13
US
I am trying to add a button to a form. When the button is clicked the number 1 is displayed, clicked again 2 is displayed and so on. I need the displayed number to be able to be saved. The whole process start over at O (zero). I have looked all over the web and this site.

Thanks

mike
 
Set the caption of the command bottun to 1 then
Code:
Option Compare Database
Option Explicit
Public ClickCount As Integer
'===========================================
Private Sub cmdClickButton_Click()
    ClickCount = Me.cmdClickButton.Caption + 1
    Me.cmdClickButton.Caption = ClickCount
End Sub
This will increase the caption by one number.


________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
If you need to display it in a textbox then place a textbox (TextBox1) on the form then add the code below.
Code:
Option Compare Database
Option Explicit
Public ClickCount As Integer
'===================================
Private Sub cmdClickButton_Click()
    ClickCount = Nz(Me.TextBox1.Value + 1, 1)
    Me.TextBox1.Value = ClickCount
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
Thanks for the information. I really do not understand where to insert the code. I tryed putting it in the control properties in On Click. I get an error Form 2 does not exist. Do you know what I am doing wrong
 
ZmrAbdulla I found my error on your first suggestion and the button is working perfectly.

Not knowing nothing about programming, trial and error can be frustrating. Thanks I will try suggestion #2 now


Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top