String Function

Returns a Variant (String) containing a repeating character string of the length specified.

Syntax

String(number, character)

The String function syntax has these arguments (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.):

Argument Description
number Required. 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.). Length of the returned string. If number contains Null (Null: A value you can enter in a field or use in expressions or queries to indicate missing or unknown data. In Visual Basic, the Null keyword indicates a Null value. Some fields, such as primary key fields, can't contain a Null value.), Null is returned.
character Required. Variant (Variant data type: The default data type for variables that don't have type-declaration characters when a Deftype statement isn't in effect. A Variant can store numeric, string, date/time, Null, or Empty data.). character code (character code: A number that represents a particular character in a set, such as the ANSI character set.) specifying the character or string expression (string expression: An expression that evaluates to a sequence of contiguous characters. Elements of the expression can be: functions that return a string or a string Variant (VarType 8); a string literal, constant, variable, or Variant.) whose first character is used to build the return string. If character contains Null (Null: A value you can enter in a field or use in expressions or queries to indicate missing or unknown data. In Visual Basic, the Null keyword indicates a Null value. Some fields, such as primary key fields, can't contain a Null value.), Null is returned.

Remarks

If you specify a number for character greater than 255, String converts the number to a valid character code using the formula:

character Mod 256

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 String function to return repeating character strings of the length specified.

Dim MyString
MyString = 5 "*"    ' Returns "*****"
MyString = 5 42    ' Returns "*****"
MyString = 10 "ABC"    ' Returns "AAAAAAAAAA"

      
 
 
Applies to:
Access 2007