Removing Extra Space (with a twist)

G

Guest

I know how to handle leading and trailing spaces. But how would you remove an
extra space (if there is an extra space) in a field that contains First Name
and Last Name, so that only 1 space is left? Thanks for your help on this one.
 
G

Graham Mandeno

Hi Richard

How about:

txtName = Trim(txtName)
Do While InStr(txtName, " ") > 0
txtName = Replace(txtName, " ", " ")
Loop

You could put this code in the AfterUpdate event procedure for your textbox
or, if you prefer, in a separate function.

I urge you to consider storing first and last name in separate fields. This
will give you all sorts of advantages such as sorting by last name and
addressing by first name (Dear Richard) to name but two.
 
G

Guest

Thank you Graham

Graham Mandeno said:
Hi Richard

How about:

txtName = Trim(txtName)
Do While InStr(txtName, " ") > 0
txtName = Replace(txtName, " ", " ")
Loop

You could put this code in the AfterUpdate event procedure for your textbox
or, if you prefer, in a separate function.

I urge you to consider storing first and last name in separate fields. This
will give you all sorts of advantages such as sorting by last name and
addressing by first name (Dear Richard) to name but two.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Richard said:
I know how to handle leading and trailing spaces. But how would you remove
an
extra space (if there is an extra space) in a field that contains First
Name
and Last Name, so that only 1 space is left? Thanks for your help on this
one.
 

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