Professional Documents
Culture Documents
Formatting
You can format fields in tables and queries and controls in forms and reports.
Formats applied to table fields persist into queries, forms, and reports.
Apply formats in reports if you don’t want them to appear in anything else.
Use the Format property.
May also use the Format function and other functions.
You can use the IIf function as a data Source, but it is more work than using the Format
property with the CanGrow and CanShrink properties.
There’s lots more to say, but it will have to wait.
Format Function
This can be used to put a date‐time stamp in a filename:
arch = libpath + "catalog" + Format(f.DateCreated, "yymmddhhmm") + ".xls"
Format Property
The Format property uses symbols to create custom formats for datasheets, forms, and
reports.
For a control, you can set this property in the controlʹs property sheet. For a field, you can
set this property in table Design view (in the Field Properties section) or in Design view of
the Query window (in the Field Properties property sheet ). You can also set the value in a
macro or Visual Basic code.
If you set a fieldʹs Format property in table Design view, that format is used to display data
in datasheets.
Some symbols apply to any data type:
Symbol Meaning
(space) display spaces as literal characters.
ʺABCʺ display anything inside quotation marks as literal characters.
! force left alignment instead of right alignment.
* fill available space with the next character.
\ display the next character as a literal character. You can also display literal characters
by placing quotation marks around them.
[color] display the formatted data in the color specified between the brackets. Available colors:
Black, Blue, Green, Cyan, Red, Magenta, Yellow, White.
Custom formats can have one or two sections. Sections are separated by “;.” Each section
contains the format specification for different data:
Section Description
first format for fields with text
second format for fields with zero‐length strings and Null values
Examples:
Property Value Data Display
@@@‐@@‐@@@@ 123456789 123‐45‐6789
@@@@@@ 12‐34‐56 123456
> test TEST
< Susan susan
@;”Unknown” [empty] Unknown
@;”Unknown” abc a
!ʺ(Cell 1) ʺ@ [empty] [empty]
!ʺ(Cell 1) ʺ@ abc (Cell 1) abc
There are custom formats. These use particular characters as symbols. Enclose separators
and any literals in quotation marks.
object.Format = mmmm dd", "yyyy
Function Int
Function Int returns the integer portion of a number with no comma separators. Without it you
can get a number with decimals and comma separating thousands. Their presence can change the
number into a string. For instance, I wrote a query to add 4 fields and divide by 4, in order to
average their values. Each field was defined as a Double, but the result of the arithmetic was a
string.