+ Reply to Thread
Results 1 to 6 of 6

Trim not working

Hybrid View

  1. #1
    Stuart
    Guest

    Trim not working

    User enters their data on the form then clicks ok.
    A sub executes, and initially I use trim on some of the
    textboxes eg:

    With FrmDataEntry
    UsrName = Trim(.TbUsrName)
    which doesn't work...and tried
    UsrName = Trim(.TbUsrName.Value)
    which doesn't work either.

    However, this statement which is executed from a different form's click
    event does work:

    If Trim(Userform1.TextBox1) = "" Then

    Education please!

    Regards.



  2. #2
    Stuart
    Guest

    Re: Trim not working

    Might be useful if I mentioned the required end result(g),
    namely to remove leading, trailing and intermediate spaces from the string.
    Apologies.

    "Stuart" <sgbooth@totalise.co.uk> wrote in message
    news:OehQ$JwWFHA.3176@TK2MSFTNGP12.phx.gbl...
    > User enters their data on the form then clicks ok.
    > A sub executes, and initially I use trim on some of the
    > textboxes eg:
    >
    > With FrmDataEntry
    > UsrName = Trim(.TbUsrName)
    > which doesn't work...and tried
    > UsrName = Trim(.TbUsrName.Value)
    > which doesn't work either.
    >
    > However, this statement which is executed from a different form's click
    > event does work:
    >
    > If Trim(Userform1.TextBox1) = "" Then
    >
    > Education please!
    >
    > Regards.
    >




  3. #3
    JE McGimpsey
    Guest

    Re: Trim not working

    VBA's Trim() function, unlike XL's TRIM(), doesn't remove internal
    spaces. Is that's what's not working?

    You could try:

    UsrName = Application.Trim(.TbUsrName)



    In article <uNnVqNwWFHA.2288@TK2MSFTNGP14.phx.gbl>,
    "Stuart" <sgbooth@totalise.co.uk> wrote:

    > Might be useful if I mentioned the required end result(g),
    > namely to remove leading, trailing and intermediate spaces from the string.


  4. #4
    Stuart
    Guest

    Re: Trim not working

    Many thanks, but had tried that with a little, but not complete luck eg, if
    the user string was:
    sgb test 1 (ie loads of spaces) then
    Application.Trim seems to result in:
    sgb test 1 (ie one space between each element of the original string)
    Is that the intended result?

    For my purposes, I'm looking to reduce the user's data string to one
    containing no 'spaces' whatsoever.

    Regards.

    "JE McGimpsey" <jemcgimpsey@mvps.org> wrote in message
    news:jemcgimpsey-245D6D.11162517052005@msnews.microsoft.com...
    > VBA's Trim() function, unlike XL's TRIM(), doesn't remove internal
    > spaces. Is that's what's not working?
    >
    > You could try:
    >
    > UsrName = Application.Trim(.TbUsrName)
    >
    >
    >
    > In article <uNnVqNwWFHA.2288@TK2MSFTNGP14.phx.gbl>,
    > "Stuart" <sgbooth@totalise.co.uk> wrote:
    >
    >> Might be useful if I mentioned the required end result(g),
    >> namely to remove leading, trailing and intermediate spaces from the
    >> string.




  5. #5
    Toppers
    Guest

    Re: Trim not working

    Try

    usrName=Replace(usrName," ","")

    HTH

    "Stuart" wrote:

    > Many thanks, but had tried that with a little, but not complete luck eg, if
    > the user string was:
    > sgb test 1 (ie loads of spaces) then
    > Application.Trim seems to result in:
    > sgb test 1 (ie one space between each element of the original string)
    > Is that the intended result?
    >
    > For my purposes, I'm looking to reduce the user's data string to one
    > containing no 'spaces' whatsoever.
    >
    > Regards.
    >
    > "JE McGimpsey" <jemcgimpsey@mvps.org> wrote in message
    > news:jemcgimpsey-245D6D.11162517052005@msnews.microsoft.com...
    > > VBA's Trim() function, unlike XL's TRIM(), doesn't remove internal
    > > spaces. Is that's what's not working?
    > >
    > > You could try:
    > >
    > > UsrName = Application.Trim(.TbUsrName)
    > >
    > >
    > >
    > > In article <uNnVqNwWFHA.2288@TK2MSFTNGP14.phx.gbl>,
    > > "Stuart" <sgbooth@totalise.co.uk> wrote:
    > >
    > >> Might be useful if I mentioned the required end result(g),
    > >> namely to remove leading, trailing and intermediate spaces from the
    > >> string.

    >
    >
    >


  6. #6
    Stuart
    Guest

    Re: Trim not working

    Seems the answer. Many thanks.
    Regards.

    "Toppers" <Toppers@discussions.microsoft.com> wrote in message
    news:3A9B4B72-A923-46BF-8C4D-2B9EB1D670D2@microsoft.com...
    > Try
    >
    > usrName=Replace(usrName," ","")
    >
    > HTH
    >
    > "Stuart" wrote:
    >
    >> Many thanks, but had tried that with a little, but not complete luck eg,
    >> if
    >> the user string was:
    >> sgb test 1 (ie loads of spaces) then
    >> Application.Trim seems to result in:
    >> sgb test 1 (ie one space between each element of the original
    >> string)
    >> Is that the intended result?
    >>
    >> For my purposes, I'm looking to reduce the user's data string to one
    >> containing no 'spaces' whatsoever.
    >>
    >> Regards.
    >>
    >> "JE McGimpsey" <jemcgimpsey@mvps.org> wrote in message
    >> news:jemcgimpsey-245D6D.11162517052005@msnews.microsoft.com...
    >> > VBA's Trim() function, unlike XL's TRIM(), doesn't remove internal
    >> > spaces. Is that's what's not working?
    >> >
    >> > You could try:
    >> >
    >> > UsrName = Application.Trim(.TbUsrName)
    >> >
    >> >
    >> >
    >> > In article <uNnVqNwWFHA.2288@TK2MSFTNGP14.phx.gbl>,
    >> > "Stuart" <sgbooth@totalise.co.uk> wrote:
    >> >
    >> >> Might be useful if I mentioned the required end result(g),
    >> >> namely to remove leading, trailing and intermediate spaces from the
    >> >> string.

    >>
    >>
    >>




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1