Access - counting scanned records

Mark H.

New member
Local time
Today, 08:17
Joined
May 20, 2022
Messages
7
I'm trying to create a counter for each time a Tracking Number is scanned into a form. Although the display box and buttons from the code below work, I can't figure out how to progressively display "y" either on an unbound box or by clicking the count button.


Private Sub Tracking_Number_AfterUpdate()

Dim x As Integer
Dim y As Integer
x = 20

Do Until y >= x
y = y + 1
Next

TotalCount = y
End Sub

Private Sub CountButton_Click()
MsgBox y
End Sub

Private Sub ResetCount_Click()
Call form_load
Call Form_Current
End Sub
 
Why are you looping at all?

First, you need a module level variable to store the count.

Then, your AfterUpdate event increments it

Your reset button click event will set it to 0 again

Code:
Option Explicit
Option Compare Database

Private m_iCount As Integer ' Defaults to 0

Private Sub Private Sub Tracking_Number_AfterUpdate()

  m_iCount = m_iCount + 1

End Sub

Private Sub CountButton_Click()

  MsgBox m_iCount

End Sub

Private Sub ResetCount_Click()

  m_iCount = 0

End Sub
 
Why are you looping at all?

First, you need a module level variable to store the count.

Then, your AfterUpdate event increments it

Your reset button click event will set it to 0 again

Code:
Option Explicit
Option Compare Database

Private m_iCount As Integer ' Defaults to 0

Private Sub Private Sub Tracking_Number_AfterUpdate()

  m_iCount = m_iCount + 1

End Sub

Private Sub CountButton_Click()

  MsgBox m_iCount

End Sub

Private Sub ResetCount_Click()

  m_iCount = 0

End Sub
Thank you so much, this is exactly what I needed. I'm fairly new to VBA coding, I was trying whatever I could find in the forums first.
 

Users who are viewing this thread

Back
Top Bottom