Microsoft Access - Can I display the value of Form_Timer on a Label in the Form.

Asked By R. on 19-Jul-12 02:48 PM
Background:  I am creating a DB that will allow barcode scanning to track usage.  It is setup to scan 3 barcodes (3 text boxes), in order.  After all 3 have been scanned, a seperate module keeps the previous values in the first 2 boxes and set focus to the last box (saves time when scanning redundant data).  In addition, I use Form_Timer to clear the form and set focus back to the first box every 30 seconds.

Question:  Can I display the real time value (in seconds) of Form_Timer on a label (named TimerDisplay) so that user can see how long until the form is reset?  My searches so far have only pointed to the new code controling a timer and forcing the update, not using the built in Form_Timer as I am below.

Any help is appreciated;
I'm using Access 2010, but creating this for the 2002-3 format.

My current working code:

Option Compare Database
  
Private Sub Entry_1_AfterUpdate()
Forms![LotNumberEntryForm].TimerInterval = 30000
End Sub
  
Private Sub Entry_2_AfterUpdate()
Forms![LotNumberEntryForm].TimerInterval = 30000
End Sub
  
Private Sub Entry_3_AfterUpdate()
Forms![LotNumberEntryForm].TimerInterval = 30000
End Sub
  
Private Sub Form_Timer()
Dim cControl As Control
     
  For Each cControl In Me.Controls
    If cControl.Name Like "Entry*" Then cControl = vbNullString
  Next
    
Me.Entry_1.SetFocus
End Sub
wally eye replied to R. on 19-Jul-12 05:49 PM

A bit of code for you:

Option Compare Database

Private Const lngTimer      As Long = 5000

Private Sub cmdReset_Click()

    Call ResetTimer

End Sub

Private Sub Form_Open(Cancel As Integer)

    Call ResetTimer

End Sub

Private Sub Form_Timer()

    If Me.txtTimer <> "0" Then
      Me.txtTimer = CLng(Me.txtTimer) - 1000
      Call UpdateTimerLabel
      If Me.txtTimer = "0" Then
        call ResetControls
      End If
    End If

End Sub

Private Sub ResetTimer()

    Me.txtTimer = lngTimer
    Call UpdateTimerLabel

End Sub

Private Sub UpdateTimerLabel()

    Me.lblTimer.Caption = CLng(Me.txtTimer) / 1000

End Sub

private sub ResetControls()

Dim cControl As Control
   
  For Each cControl In Me.Controls
  If cControl.Name Like "Entry*" Then cControl = vbNullString
  Next
    
Me.Entry_1.SetFocus

end sub

There are three controls on my form, you won't need the cmdReset.

txtTimer is a hidden control that is updated with the time remaining till next reset.  lblTimer is the displayed timer.  You would have your _AfterUpdate events call the ResetTimer procedure.

R. replied to wally eye on 06-Aug-12 04:02 PM
Hi Wally Eye,

My apologies for the delay in responding.  Your code did just as I needed it to, I really appreciate you sharing it with me.

SOLVED