Microsoft Access VBA Macro Programming

(Tina Sui) #1
You can use the following parameters for the interval:

Setting Description
Yyyy Year
Q Quarter
M Month
Y Day of Year
D Day
W Weekday
Ww Week
H Hour
M Minute
S Second

Using DateAdd to Pause Your Code


Use theDateAddfunction to create a function to pause your code for a few seconds. You
may need to do this for operational reasons or to display a splash screen for a brief moment.
Enter the following code into a module:


Function AccessWait(Target As Long)


TimeWait = DateAdd("s", Target, Time)
Do Until Time >= TimeWait


Loop


End Function


You can call this from VBA code by using the following code:

X = AccessWait( 10 )


This will stop processing for 10 seconds.
This function has one parameter passed to it, which is the number of seconds to wait. It
uses theDateAddfunction to add the number of target seconds to the current time and puts
the result into a variable called TimeWait.
It then uses a Do..Until Loop to hold all processing until the current time is greater than or
equal to the variable TimeWait.
This is a simple but effective methodology to pause processing for a set period of time.


Chapter 28: Using the DateAdd Function 303

Free download pdf