Microsoft Access VBA Macro Programming

(Tina Sui) #1

Weekday


TheWeekdayfunction returns an integer between 1 (Sunday) and 7 (Saturday) that
represents the day of the week for a date expression:

Weekday (dateexpression)
MsgBox WeekDay("6-Mar-2003")

This will return the value 5, which is Thursday.
This function can be useful if you want a date to always default to a particular day of the
week. For example, if you always want a date to show the week ending Friday for the current
week, you could use the following formula:

MsgBox Now - WeekDay(Now) + 6

TheWeekdayfunction starts from Sunday, so it reducesNowback to the last Sunday and
then adds 6 to get to Friday. You can also use it to calculate the number of working days
between two dates:
For n = DateValue("1-Jan-03") To DateValue(" 18 -Jan-03")

If Weekday(n) <> 1 Or Weekday(n) <> 7 Then

WorkDay = WorkDay + 1

End If
Next n

MsgBox WorkDay

WorkDaywill return the value of 13, which is the number of working days between the two
dates.

The SendKeys Command


TheSendKeyscommand is not really a function but rather a command statement. A command
statement like this can be used in a function or a subroutine. It allows you to command another
application by sending keypresses to it, exactly the same as if you were typing at the keyboard
into that application. It effectively simulates keypresses on the keyboard and can be used for
low-level automation of programs that do not support OLE automation.

62 Microsoft Access 2010 VBA Macro Programming

Free download pdf