Home » Forms » Microsoft Access Form Designs: Using VBA With On Timer Event

Microsoft Access Form Designs: Using VBA With On Timer Event

Microsoft Access Form Designs: Using VBA With On Timer Event

This Access form will self-destruct in 10, 9, 8, 7….

Using the unknown or unused Timer Event for your Microsoft Access form designs can be quite effective and really automate your background processes.

I was recently asked if this application has a timer control which one could illustrate as a count down or trigger code on a set time.

Microsoft Access

You can show a real time count down by using basic controls like a text box or launch another form (or report) or even check the status of the application; for example, if it still has a live connection across a LAN network.

Microsoft Access Form Designs: Using VBA With On Timer Event

So here are the basic steps which you can further enhance for your own designs. I’m going to add a Label, Text Box and apply some basic formatting with VBA code (and you won’t need to be a master ‘expert’ programmer for the code additions required).

Start a new blank form in design view and add a Label and Text Box control. If you need to really master Microsoft Access forms, consider my eBook module.

I’ve named my Text Box as ‘txt_Counter‘ and applied some basic formatting including a large font, coloured white with a red fill (background).

Set the following form’s Timer Interval to 10000 which is measured in milliseconds as I wish to count just 10 seconds (see image below). 

Microsoft Access

Now we need to add some VBA code by loading the ‘On Open’ and ‘On Timer’ event procedures. This will open the Visual Basic Editor view (which is where your VBA code is managed).

 Using the illustrating below, add the following code to the two sub procedures. 

Microsoft Access

Save your changes and run the form!

The Access VBA code triggers the ‘On Open’ event when the form opens and this will simply set the value of my Text Box to 10. This is optional as I could have set the default property to this control instead – just showing off here!

The main event which needs the Timer Interval property set correctly (10 seconds for this example) starts to count this number of seconds in the background and the Text Box control is simply being refreshed every second subtracting 1 each time.

A logical test is added so it will close the form when this value hits 0 (zero).

There you go! Working with Microsoft Access form designs can be fun and very polished and professional indeed.

Check out this blog website for other articles on Microsoft Access databases by using the search box provides (top right area).

Tags: , , , , , ,

4 Responses so far.

  1. Michel says:

    1.000 miliseconds = 1 second

  2. Don Miller says:

    Can you let me have the code for opening a menu (form with buttons on it) where the buttons don’t appear at all for 5 seconds please.

    • benadt2017 says:

      You can adapt the sample ode used. Just need to attach it to a form (or another object or function) which will call the form with the command buttons (as menu items) setting the timer control to reflect 5 seconds.