You are on page 1of 2

Microsoft Access Techniques

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.  

Format Property for Text and Memo Data Types


ƒ The Format property uses symbols to create custom formats. 
Symbol  Description 
@    text character (or space) is required 
&    text character is not required 
<    force all characters to lowercase 
>    force all characters to uppercase 

Revision: 9/2/2012 Page 35 of 119


Copyright 2001–2012 by Susan J. Dorey
Microsoft Access Techniques

ƒ 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 

Format Property for Dates


ƒ There are predefined formats:  “Short Date”, “General Date”, “Long Date”, “Long Time”, 
etc. 
object.Format = "Short Date"

ƒ 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. 
 

Revision: 9/2/2012 Page 36 of 119


Copyright 2001–2012 by Susan J. Dorey

You might also like