LTrim, RTrim, and Trim Functions

Returns a Variant (String) containing a copy of a specified string without leading spaces (LTrim), trailing spaces (RTrim), or both leading and trailing spaces (Trim).





The required string argument (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.) is any valid 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.). If string 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.


 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 LTrim function to strip leading spaces and the RTrim function to strip trailing spaces from a string variable. It uses the Trim function to strip both types of spaces.

 Tip    Expression Builder with IntelliSense in Access 2010 helps you with your expressions. Read an article or try Office 2010.Try Office 2010

Dim MyString, TrimString

MyString = "  <-Trim->  "    ' Initialize string.

TrimString = LTrim(MyString) 
' TrimString = "<-Trim->  ".

TrimString = RTrim(MyString)
' TrimString = "  <-Trim->".

TrimString = LTrim(RTrim(MyString)) 
' TrimString = "<-Trim->".

' Using the Trim function alone
' achieves the same result.
TrimString = Trim(MyString) 
' TrimString = "<-Trim->".

Applies to:
Access 2007