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.
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).
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.
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: access form designs, how do you use microsoft access, how to use the on timer event, microsoft access database vba, MS Access, ms access forms, on time event in vba
1.000 miliseconds = 1 second
Timer Interval property with a value of 1,000 = 1,000 milliseconds which = 1 second.
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.
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.