Mouse Click Counter On Access Form

This post will demonstrate how you can count the number of clicks
on your button in a certain time frame.

It will function like a game .

Here is the database form all in one:

Option Compare Database

Public m_dteStartTime As Date
Public m_dteStopTime As Date

Private Sub btnClicker_Click()
    Dim intValue As Integer
    Dim rst As Recordset
    
    'read, write
    Set rst = CurrentDb.OpenRecordset("tblCurrentCount", dbOpenDynaset)
    
    intValue = DLookup("[cnt_current_count]", "tblCurrentCount")
    
    intValue = intValue + 1
    rst.Edit
    rst.Fields("cnt_current_count") = intValue
    rst.Update
    
    rst.Close
    Set rst = Nothing
    
    
    Me.lblCount.Caption = "The current count is " & intValue
    DoEvents
    
End Sub



Private Sub btnRestartCounter_Click()

    Dim rst As Recordset
    
    Set rst = CurrentDb.OpenRecordset("tblCurrentCount", dbOpenDynaset)
    
    rst.Edit
    rst.Fields("cnt_current_count") = 0
    rst.Update
    
    rst.Close
    Set rst = Nothing

    Me.lblCount.Caption = "The current count is 0"
    Me.lblResult.Caption = "Ready..."
    DoEvents
    
    'reset the modular variables
    m_dteStartTime = 0
    m_dteStopTime = 0
    
End Sub

Private Sub btnStart_Click()
    Me.TimerInterval = 1000
    m_dteStartTime = Now()
End Sub

Private Sub btnStop_Click()
    Dim intResult As Integer
    Dim intElapsedTime As Integer

    Me.TimerInterval = 0
    
    m_dteStopTime = Now()

    intElapsedTime = Format(m_dteStopTime - m_dteStartTime, "ss")
    
    'get the current count
    intValue = DLookup("[cnt_current_count]", "tblCurrentCount")
    
    Me.lblResult.Caption = intValue & " clicks in " & intElapsedTime & " seconds"
    DoEvents
    
    
End Sub

Private Sub Form_Timer()
    Me.lblTimer.Caption = Now()
    DoEvents
    
End Sub

Here is the database for an example.

mouse click counter.accdb

Watch how it’s done:



Offsite Related Information:

“Go Fund Me” Page


($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: ,