Access VBA Macro Programming

(Joao Candeias) #1
A number of characters can be used to create a user-defined format
Date formats, like number formats, can use sections. One section only applies to all data;
two sections means that the first section applies to all data and the second to zero-length
strings and null. For examples, look at the following table:

Format String Definition
mm/dd/yy 01/03/03
dd-mmm-yyyy 01-Mar-2003
hh:mm a.m./p.m.

You can also use certain characters within your format string to create formatting, as
shown in Table 5-6.
Some examples of using theFormatfunction on numbers and strings are shown here:

MsgBox "This is " & Format(" 1000 ", "@@@,@@@")
MsgBox "This is " & Format(" 1000 ", "&&&,&&&")
MsgBox Format("richard", ">")

Date and Time Functions


A number of functions deal specifically with date and time. These are included in this
section.

Now


TheNowfunction returns the current date and time:

MsgBox Now

This displays the short date and time formats from the Windows Control Panel.

56 Microsoft Access 2010 VBA Macro Programming


Character Definition
@ Character placeholder. Displays a character or a space. If there is a character, it is
displayed; otherwise, a space is displayed.
& Character placeholder. Display a character or nothing. If there is a character, display it;
otherwise, display nothing.
< Force lowercase.
> Force uppercase.
! Force placeholders to fill from left to right.
Table 5-6 Additional Format Characters
Free download pdf