Literals

VBA provides three types of literals that you can combine with operators to create expressions. The following list describes these types of literals:

  • Numeric literals are typed as a series of digits, including the arithmetic sign and decimal point if applicable. You don't have to prefix positive numbers with the plus sign; Access assumes positive values unless the minus sign is present. Numeric literals can include E or e and the sign of the exponent to indicate an exponent in scientific notation for example, -1.23E-02.

  • Text (or string) literals can include any printable character, plus unprintable characters returned by the Chr function. The Chr function returns the characters specified by a numeric value from the ANSI character table (similar to the ASCII character table) that Windows uses. For example, Chr(9) returns the Tab character. Printable characters include the letters A through Z, numbers 0 through 9, punctuation symbols, and other special keyboard symbols such as the tilde (~). VBA expressions require that you enclose string literals within double quotation marks (""). Combinations of printable and unprintable characters are concatenated with &. For example, the following expression separates two strings with a newline pair:

     "First line" & Chr(13) & Chr(10) & "Second line" 

    Chr(13) is the carriage return (CR), and Chr(10) is the line-feed (LF) character; together they form the newline pair. VBA has a constant vbCrLf, which you can substitute for Chr(13) & Chr(10).

    When you enter string literals in the cells of tables and Query Design grids, Access adds the quotation marks for you. In other places, you must enter the quotation marks yourself.

  • Date/Time VBA/Jet literals are enclosed within number or pound signs (#), as in the expressions #1-Jan-1980# or #10:20:30#. If Access detects that you're typing a date or time in one of the standard Jet Date/Time formats into a Design grid, it adds the enclosing pound signs for you. Otherwise, you must type the # signs.

T-SQL

T-SQL numeric literals are identical to Jet's, but, as mentioned earlier, string (character) literals are enclosed between single quotes ('string'). T-SQL doesn't have a Date/Time identifier; you must supply date values as quoted strings in one of the standard formats that T-SQL recognizes, such as '3/15/2003'.



Special Edition Using Microsoft Office Access 2003
Special Edition Using Microsoft Office Access 2003
ISBN: 0789729520
EAN: 2147483647
Year: 2005
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net