Results 1 to 8 of 8
  1. #1
    kiwichick is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    31

    Post Concatenate parts of looped string


    I have a textbox control on my form where I want [] to be placed around each word of the content. The content could be any number of words. For example:

    Content:
    Crassula ovata Gollum
    Becomes:
    [Crassula] [ovata] [Gollum]

    I've found some code online that splits the string then uses a loop to place [] around each word, but I can't figure out how to concatenate the string back together. Any help would be greatly appreciated. Here is the code I'm using:

    Code:
    ' Button only used for testing. Will use control when the code is sorted.
    Private Sub Command63_Click()
    Dim wordlist As String
    Dim arrayofWords
    Dim i
    ' String only used for testing. Will use control when the code is sorted.
    wordlist = "Crassula ovata Gollum"
    
    arrayofWords = Split(wordlist)
    
    For i = LBound(arrayofWords) To UBound(arrayofWords)
        arrayofWords(i) = "[" & arrayofWords(i) & "]"
        ' Don't know what to put here to concatenate.
        ' MsgBox only used for testing.
        MsgBox arrayofWords(i)   
    Next
    
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How about:

    Code:
      Dim wordlist As String
      Dim arrayofWords
      Dim i
      Dim strList As String
      ' String only used for testing. Will use control when the code is sorted.
      wordlist = "Crassula ovata Gollum"
    
      arrayofWords = Split(wordlist)
    
      For i = LBound(arrayofWords) To UBound(arrayofWords)
        strList = strList & "[" & arrayofWords(i) & "]"
      Next
      MsgBox strList
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    See if this helps:
    Attached Files Attached Files

  4. #4
    kiwichick is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    31
    Quote Originally Posted by pbaldy View Post
    How about:

    Code:
      Dim wordlist As String
      Dim arrayofWords
      Dim i
      Dim strList As String
      ' String only used for testing. Will use control when the code is sorted.
      wordlist = "Crassula ovata Gollum"
    
      arrayofWords = Split(wordlist)
    
      For i = LBound(arrayofWords) To UBound(arrayofWords)
        strList = strList & "[" & arrayofWords(i) & "]"
      Next
      MsgBox strList
    Thanks pbaldy, it works but there are no spaces between the words.

  5. #5
    kiwichick is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    31
    Quote Originally Posted by ssanfu View Post
    See if this helps:
    Thanks ssanfu, that works but, as you've made it a standalone piece of code, hopefully I can make it work with what I have already.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by kiwichick View Post
    Thanks pbaldy, it works but there are no spaces between the words.
    Easy enough to add a space after the closing bracket.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    kiwichick is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    31
    Quote Originally Posted by pbaldy View Post
    Easy enough to add a space after the closing bracket.
    Thanks pbaldy, I did think of that but wasn't sure about the trailing space. Have used RTrim() to deal with that. Thanks for your help

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Concatenate Build String
    By shank in forum Modules
    Replies: 3
    Last Post: 06-11-2019, 10:30 AM
  2. query to split concatenated string into separate parts
    By ankur_bhardwaj in forum Access
    Replies: 9
    Last Post: 07-12-2016, 12:21 PM
  3. Replies: 4
    Last Post: 04-15-2013, 04:03 PM
  4. How to Concatenate String Criteria
    By ColPat in forum Programming
    Replies: 2
    Last Post: 06-26-2010, 08:48 PM
  5. concatenate string using loop
    By nengster in forum Programming
    Replies: 0
    Last Post: 02-23-2009, 08:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums