How to Stop an Access Form Timer After 30 Days Using VBA
Question details
The user wants to use VBA to make a specific date field flash on a form for 30 days, after which the form timer should automatically stop.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Creating a visual alert on a database form where a date field alternates colors to grab attention but needs to automatically stop flashing after a 30-day period.
- Observed behavior
- The form utilizes a timer to alternate the background and foreground colors of the target field. Once 30 days have passed from the specified date, the timer interval must be set to 0 to disable the flashing effect.
Ensure you have a backup of your Access database before modifying the form's VBA code, and verify the name of the date text box control you want to manipulate.
Use VBA DateAdd Function to Disable the Timer
Implement a VBA script on the form's Timer event that evaluates the date difference and sets the TimerInterval to 0 once the 30 days have elapsed.
This method evaluates whether 30 days have passed since the date logged in your specified field. As long as the current date is within that 30-day window, the code alternates the background and foreground colors of the field to create a flashing effect. Once the period expires, it disables the form timer entirely.
Open your Microsoft Access database in Design View for the specific form. Navigate to the Property Sheet, select 'Form' from the drop-down, and set the 'Timer Interval' to your preferred flashing speed (e.g., 500 for a half-second interval).
In the Property Sheet under the Event tab, click the ellipsis (...) next to 'On Timer'. Choose 'Code Builder' to open the VBA editor for the Form_Timer event.
Add a conditional statement to check if the field is not null and if the date is within the 30-day window. Use: If Not IsNull(Me.CANDATE) Then If DateAdd("d", 30, Me.CANDATE) > Date() Then
Inside the active date condition, add logic to switch colors. For example: If Me.CANDATE.BackColor = vbWhite Then Me.CANDATE.BackColor = vbRed Else Me.CANDATE.BackColor = vbWhite.
Add an Else statement for the date check to turn off the timer when the 30 days have passed. Include: Else Me.TimerInterval = 0 End If.

Looking for a Lightweight Office Suite?
While Microsoft Access handles complex databases, for your everyday spreadsheet, document, and presentation tasks, WPS Office provides a fully compatible, free, and lightweight alternative to Microsoft Office. It flawlessly handles Excel macros and VBA scripts without the heavy resource requirements.
- 1. Download WPS Office: Visit the official WPS website and download the free installation package for your operating system.
- 2. Install the Software: Run the installer and follow the simple on-screen instructions to set up WPS Office on your computer.
- 3. Open Your Office Files: Launch WPS Spreadsheet, Writer, or Presentation and open your existing Microsoft Office files with perfect formatting retention.

Frequently Asked Questions
What unit of measurement does the Access TimerInterval use?
In Microsoft Access, the TimerInterval property is measured in milliseconds. Setting the interval to 1000 will trigger the Form_Timer event once every 1 second.
Why isn't my form timer triggering the VBA code?
Ensure that the form's TimerInterval property is initially set to a value greater than 0 in the Property Sheet, and verify that your VBA code is placed specifically inside the Form_Timer() event procedure.
Can I use this VBA method to check for a different number of days?
Yes. You can easily modify the DateAdd function in the VBA code by changing the numeric argument (e.g., changing 30 to 60) to set a different expiration period for the flashing alert.




