Trim()
will remove trailing spaces. So, if your string values end with something that looks like a space, but is not removed by Trim()
, it may not actually be a space character. Another possibility would be a space followed by an invisible character.
Either way, it would be useful to know what the last character actually is.
SELECT Asc(Right(your_string, 1)) AS ascii_value
FROM YourTable;
Once you know what that character is, you can decide how best to get rid of it.
I don't know what the best way is for you. From the details which have emerged in the comments, it appears the troublesome character is a non-breaking space, ASCII 160. You want to discard that character when it occurs at the end of a string. Perhaps you also want to discard any regular space characters which precede the non-breaking space in that situation. But if non-breaking spaces are present elsewhere in the string, you want to keep those.
Additionally it seems you want to do this for existing data stored in the Access table and for new incoming data collected with your VBScript scraping procedure. From VBScript, a query can't use custom VBA functions or the Replace()
function. So I don't know what to say about the new data without seeing your scraping code. For existing data, you could use an UPDATE
statement, similar to the one you suggested in your question, which should work from either VBScript or from within an Access session.
UPDATE YourTable
SET your_string = Left(your_string, Len(your_string) -1)
WHERE Asc(Right(your_string, 1)) = 160;
If you also want to discard any spaces which are present ahead of the trailing non-breaking space, incorporate Trim()
.
UPDATE YourTable
SET your_string = Trim(Left(your_string, Len(your_string) -1))
WHERE Asc(Right(your_string, 1)) = 160;