Do I have to worry about Access storing Trailing or leading spaces

S

Steve Stad

Do I have to worry about Access storing Trailing or leading spaces or do I
need code such as......

Private Sub NAME_AfterUpdate()
Me.[NAME] = Trim(Me.[NAME])
End Sub
 
S

Stuart McCall

Steve Stad said:
Do I have to worry about Access storing Trailing or leading spaces or do I
need code such as......

Private Sub NAME_AfterUpdate()
Me.[NAME] = Trim(Me.[NAME])
End Sub

Trailing spaces are stripped out by Access, but leading spaces aren't. So
you can use LTrim instead of Trim (slightly faster, if only noticeable in
long loops).
 
S

Steve Stad

Thanks Stuart - but are you aware of being able to copy/paste a word or
string with a trailing space from an external source (e.g., web page, etc)
into access?

Stuart McCall said:
Steve Stad said:
Do I have to worry about Access storing Trailing or leading spaces or do I
need code such as......

Private Sub NAME_AfterUpdate()
Me.[NAME] = Trim(Me.[NAME])
End Sub

Trailing spaces are stripped out by Access, but leading spaces aren't. So
you can use LTrim instead of Trim (slightly faster, if only noticeable in
long loops).


.
 
S

Stuart McCall

Steve Stad said:
Thanks Stuart - but are you aware of being able to copy/paste a word or
string with a trailing space from an external source (e.g., web page, etc)
into access?

Stuart McCall said:
Steve Stad said:
Do I have to worry about Access storing Trailing or leading spaces or
do I
need code such as......

Private Sub NAME_AfterUpdate()
Me.[NAME] = Trim(Me.[NAME])
End Sub

Trailing spaces are stripped out by Access, but leading spaces aren't. So
you can use LTrim instead of Trim (slightly faster, if only noticeable in
long loops).

I wasn't aware of that feature. I take it you've discovered this to be the
case. In that case yes, Trim is the correct function to use.
 
D

Dirk Goldgar

Steve Stad said:
Thanks Stuart - but are you aware of being able to copy/paste a word or
string with a trailing space from an external source (e.g., web page, etc)
into access?


I think that if you copy and paste into a text box or a cell of a datasheet,
trailing spaces will be removed. However, that is true for the character
that Access recognizes as a space, Chr(32), and would not be true for some
other characters that may appear to be spaces; for example, Chr(160).
However, Trim() won't remove such characters, either.
 
S

Steve Stad

Thanks Dirk,
I must have encountered a Chr(160) space in the past. I eliminated these
with a validation rule in the tbl design - and never knew the difference
between chr(160) and chr(32).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top