Access - How To Remove Spaces Between Words In TextBox And Replace With Hyphens

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gcoaster
    New Member
    • Sep 2007
    • 117

    #1

    Access - How To Remove Spaces Between Words In TextBox And Replace With Hyphens

    Hello All

    GOAL - I would like to have one text box where I enter a sentence

    txtKeywords: Access Is For Smart People Smarter Than I

    I would like to create a button when clicked moves [txtKeywords] into another textbox [txtKeywordscomb ined] field and removes the spaces between the words and adds hyphens

    txtKeywordscomb ined: Access-Is-For-Smart-People-Smarter-Than-I


    Would I use the 'Replace' command in even procedures to do this? Another way? Example?
    Thank you!
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    The Replace() function is way to go. I can't think of a reason to not to use it. The next simplest method would be the Split() function using the space as the delimiter and then use the Join() function using the hyphen as the delimiter. This method would allow you to manipulate the words individually within the array after you split it but before you join it back together. If this isn't necessary though, I wouldn't use it. Is there a reason that you hesitate to use the Replace() function?

    Comment

    • gcoaster
      New Member
      • Sep 2007
      • 117

      #3
      Thank you for your fast reply!
      I think i got it to work

      Code:
      =Replace([imgkeywords]," ","-")
      But i have a #Type! error

      I am trying to figure out how to add option to make words lowercase as well and add that into the mix. Access is fun when it work!

      Lower case for instance

      Before: This Is The Senence
      After: this-is-the-senence


      thank you Seth!

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        Only one question per thread please.

        Can you verify that the imgkeywords field is a text data type? Try replacing the space with something else, like a comma and see if that changes anything. I don't think that it would be a problem, but a hyphen is also a minus sign in numbers, so I'm just trying to eliminate that possibility. Based on your formula, it looks like you have this in the control source or the default value properties of a textbox on a form. Is this form bound to a query or a table?

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          You can use Replace(). However, you must ensure the data passed is textual. That often means replacing Null with a value. Something like :
          Code:
          txtKeywordsCombined: LCase(Replace(Nz([txtKeywords],''),' ','-'))
          PS. In this case the LCase() is more of an aside than a separate question so we'll allow dropping it in there as long as it doesn't become part of any discussion in here.

          Comment

          • gcoaster
            New Member
            • Sep 2007
            • 117

            #6
            Thanks NeoPa! You Rock

            Comment

            Working...