Adding a Clock to a Form

Adding a clock to a form involves a little VBA programming, but not too much. For those who are quite unfamiliar with this, then I will step you through it.

The objective of this tip is to add a dynamic clock to a form on your database.

To do this:

  • Open a form, any form, and add an unbound text box;
  • Open the properties window for this text box;
  • Click on the ‘Format’ tab and change the Format to ‘Long Time’;
  • Then, click on the ‘Other’ tab and change the ‘Name’ of the text box to txtClock;
  • Then, click on the ‘Data’ tab and type into the ‘Control Source’ section:
  • =time()

Now, if you open your form in Normal view the unbound text box will display the current time. But, you will notice if you leave the form open the time will not change. We are going to fix this.

  • Re-open the form in Design view and open the properties window for the form;
  • Click on the ‘Event’ tab and then scroll down until you find the following two items:
  • On Timer; and Timer Interval.
  • Set the timer interval to 1000.
  • Then, place your cursor next to ‘On Timer’ - a button with 3 dots on it should appear.
  • Click on this button:
  • Choose ‘Code Builder’ from the list displayed and then click on OK to close the window and to create a Subprocedure.

The VBA window will open with the following two lines of code:

Private Sub Form_Timer()

End Sub

Between these two lines of code add the following line of code:

Me.txtClock.Requery

Close the VBA window and open the form in Normal view.

You have completed Adding a Clock to a Form.... well done Your clock should now be operating.

Finished with Adding a clock to a form; then return to 'Microsoft Access Forms'

or Return to Simply-Access Home Page