Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Removing Extra Space (with a twist)

Discussion in 'Information Technology' started by Richard, Jul 28, 2006.

  1. Richard

    Richard
    Expand Collapse
    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.
     
  2. Loading...


  3. Graham Mandeno

    Graham Mandeno
    Expand Collapse
    Guest

    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" <Richard@discussions.microsoft.com> wrote in message
    news:7965518B-E268-40E5-BD51-67211F38D807@microsoft.com...
    >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.
     
  4. Richard

    Richard
    Expand Collapse
    Guest

    Thank you Graham

    "Graham Mandeno" wrote:

    > 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" <Richard@discussions.microsoft.com> wrote in message
    > news:7965518B-E268-40E5-BD51-67211F38D807@microsoft.com...
    > >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.

    >
    >
    >
     

Share This Page