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

  • Thread starter Thread starter Steve Stad
  • Start date Start date
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
 
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).
 
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).


.
 
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.
 
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.
 
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).
 
Back
Top