MS Access Space() Function

The Space() function in MS Access generates a string containing a specified number of space characters. This function might seem simple, but it's surprisingly useful for string padding, formatting, or creating strings of a specific length for various purposes within your MS Access applications.



Space(): Definition and Usage

Space() is frequently used to create strings filled with spaces. This is often needed for tasks such as formatting data (like aligning text columns), padding data to ensure consistent lengths, or generating strings of a particular size for other string manipulation tasks.

Syntax

Syntax

Space(number)
      

Parameter Values

Parameter Description
number The number of spaces to generate. This is required and must be a non-negative integer.

Example

Generating a String of Spaces

This example generates a string containing five spaces.

Syntax

SELECT Space(5) AS SpaceString;
      
Output

SpaceString
------------
        (Five spaces will be displayed here)
      

**Note:** The output above will visually show five spaces when the query is executed in an MS Access environment. The formatting in this text display prevents you from seeing the spaces directly. Providing a negative number as input to the `Space()` function will result in an error.