2

Does anyone know if there is a way to create a stopwatch in MS Access? I'm looking for a way to have a stopwatch "start" at the point that someone clicks "new" record for a particular form, and have the stopwatch "end" at the point the person saves the information entered in the form? Ideally, for each record in the table, I would like to have an additional column displaying the time it took to create the form.

Any suggestions/ideas?

2
  • I'm curious what is the purpose of tracking the amount of time it takes your users to insert each new record?
    – HansUp
    Apr 9, 2012 at 18:30
  • Do you want the timer resolution in seconds, milliseconds, microseconds, picoseconds.?
    – Gutzofter
    Aug 4, 2012 at 16:45

2 Answers 2

2

Try this You could set the onClick to "new" and you can put in a simple if statement to allow it to stop on the save action

2

When you click the new button, the form's On Current event will fire. You can distinguish whether the current record is a new or existing record by examining the form's NewRecord property.

I added a Long Integer field named seconds_for_insert to my table. Then I created a form whose record source is a query based on that table. The form includes a text box name txtSeconds_for_insert which is bound to the record source seconds_for_insert field. Here is my form's code:

Option Compare Database
Option Explicit
Dim blnNewRecord As Boolean
Dim dteStartTime As Date

Private Sub Form_BeforeInsert(Cancel As Integer)
    Me.txtSeconds_for_insert = DateDiff("s", dteStartTime, Now())
End Sub

Private Sub Form_Current()
    blnNewRecord = Me.NewRecord
    If blnNewRecord Then
        dteStartTime = Now()
    End If
End Sub

If your source table contains an autonumber field, Access will save the new record as soon as you type anything into one of the bound controls. Any remaining data you add to that "new" record will be saved with an update rather than an insert operation. So in that situation, use Form_BeforeUpdate instead of Form_BeforeInsert.

Private Sub Form_BeforeUpdate(Cancel As Integer)
    If blnNewRecord Then
        Me.txtSeconds_for_insert = DateDiff("s", dteStartTime, Now())
    End If
End Sub

The txtSeconds_for_insert text box doesn't have to be enabled or even visible for this to work. You may prefer to set Visible = No to avoid distracting the users, or if you don't want them to know you're tracking that information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.