Public Function RemSpace(ByVal strSource As String) As String
Dim strWork As String
strWork = Trim$(strSource)
Do While InStr(1, strWork, Space$(2)) <> 0
strWork = Replace(strWork, Space$(2), Space$(1))
Loop
RemSpace = strWork
End Function
UPDATE tblTest SET tblTest.TestText = RemSpace([TestText]);
There might be some performance benefit in replacing Space$(2) with " "
(two spaces) and Space$(1) with " " (one space). I used the Space$()
function because it's easier to see what the code is doing that way.
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
SD said:
Data that was imported from another source contains spacing within the
text. For example, I imported several records and many of the fields
contain text such as "This is only a test". How do I remove the spaces
between "is" and "only". Neither of the Trim functions (LTRIM, RTRIM,TRIM)
works for this case. Any ideas on how to remove the excess spaces in the
middle of the text field?