Access: Trim Function

In Access, the Trim function returns a copy of a string with leading and trailing spaces removed.

The syntax for the Trim function is:

Trim ( string )

The string argument can be any string expression. If string contains Null, Null is returned.

Example

Trim (" WebCheatSheet ")         returns "WebCheatSheet" 
Trim ("tutorials ")                     returns "tutorials"
Trim (" articles")                      returns "articles"

VBA Code

Dim MyString, TrimString 
MyString = " Access "
TrimString = Trim(MyString)

This example uses the Trim function to strip both types of spaces. Now the MyString variable would contain the value “Access”.

SQL query

You can also use the Trim function in a query.

SELECT Trim([ItemDesired]) AS Expr1 
FROM Orders
admin

admin

Leave a Reply

Your email address will not be published.