Chr Function

Returns a String (String data type: A fundamental data type that holds characters, one character per 2 bytes. A fixed-length string can contain 1 to 64K characters; a variable-length string can contain 1 to 2 billion.) containing the character associated with the specified character code (character code: A number that represents a particular character in a set, such as the ANSI character set.) .

Syntax

Chr(charcode)

The required charcode argument (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.) is a Long (Long data type: A fundamental data type that holds large integers. A Long variable is stored as a 32-bit number ranging in value from -2,147,483,648 to 2,147,483,647.) that identifies a character.

Remarks

Numbers from 0 – 31 are the same as standard, nonprintable ASCII (ASCII: American Standard Code for Information Interchange (ASCII) 7-bit character set used to represent letters and symbols found on a standard U.S. keyboard.) codes. For example, Chr(10) returns a linefeed character. The normal range for charcode is 0 – 255. However, on DBCS (DBCS: A character set that uses 1 or 2 bytes to represent a character, allowing more than 256 characters to be represented.)systems, the actual range for charcode is -32768 to 65535.

 Note   The ChrB function is used with byte data contained in a String. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte. The ChrW function returns a String containing the Unicode (Unicode: A character encoding standard developed by the Unicode Consortium. By using more than one byte to represent each character, Unicode enables almost all of the written languages in the world to be represented by using a single character set.) character except on platforms where Unicode is not supported, in which case, the behavior is identical to the Chr function.

 Note    Visual Basic for the Macintosh does not support Unicode strings. Therefore, ChrW(n) cannot return all Unicode characters for n values in the range of 128 – 65,535, as it does in the Windows environment. Instead, ChrW(n) attempts a "best guess" for Unicode values n greater than 127. Therefore, you should not use ChrW in the Macintosh environment.

Example

 Note   Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

This example uses the Chr function to return the character associated with the specified character code.

Dim MyChar
MyChar = 65    ' Returns A.
MyChar = 97    ' Returns a.
MyChar = 62    ' Returns >.
MyChar = 37    ' Returns %.
 
 
Applies to:
Access 2007