Remove leading spaces

E

EllenM

Sometimes when importing a table from Excel, a leading space gets inserted in
the field, which messes up queries. I tried to remove this space with a find
and replace (this column shouldn't have had any spaces), but to no avail. I
wound up removing them by hand.

Is there an easy way to remove leading spaces in a field?

Thanks in advance,
Ellen
 
B

Beetle

You could run an Update query using the LTrim Function

UPDATE tblMyTable SET MyField = LTrim("MyField");

LTrim - removes leading spaces
RTrim - removes trailing spaces
Trim - removes both leading and trailing spaces
 
D

Duane Hookom

DON'T, that query would be dangerous.
UPDATE tblMyTable SET MyField = LTrim("MyField");
This would end up with MyField containing the value "MyField".

Try:
UPDATE tblMyTable SET MyField = LTrim([MyField]);
 
B

Beetle

Thanks for catching my mistake Duane. Not sure what I was thinking
there.
--
_________

Sean Bailey


Duane Hookom said:
DON'T, that query would be dangerous.
UPDATE tblMyTable SET MyField = LTrim("MyField");
This would end up with MyField containing the value "MyField".

Try:
UPDATE tblMyTable SET MyField = LTrim([MyField]);

--
Duane Hookom
Microsoft Access MVP


Beetle said:
You could run an Update query using the LTrim Function

UPDATE tblMyTable SET MyField = LTrim("MyField");

LTrim - removes leading spaces
RTrim - removes trailing spaces
Trim - removes both leading and trailing spaces
 

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