Access VBA Macro Programming

(Joao Candeias) #1

Date


Datereturns the current date in short format as defined in the Windows Control Panel:


MsgBox Date


Time


TheTimefunction returns the current system time:


MsgBox Time


The preceding line is an example of setting the time to 11 minutes past one in the afternoon.


DateAdd


DateAddallows the addition and subtraction of a specified time interval to a date. This
function is dealt with in more detail in Chapter 28. The syntax is as follows:


DateAdd (interval, number, date)


Intervalis a string that expresses the interval of time you want to add.
The following table provides a list of interval types:


Time Period Interval
Year Yyyy
Quarter Q
Month M
Day of Year Y
Day D
Weekday W
Week Ww
Hour H
Minute N
Second S

Numberis a numeric that determines the number of intervals you want to add. A negative
value is allowed and will prompt subtraction from the date.
Dateis the date being added to, or the name of a variant containing, the date. This example
will add one month to January and return 1-Feb-03:


MsgBox DateAdd ("m",1,"1-Jan-03")


Chapter 5: Strings, Functions, and Message Boxes 57

Free download pdf