Results 1 to 8 of 8
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    text box concatenation - give every line something

    Is there a method to go through a text box on a form in vba that for every line (return) it adds something to it?



    I am using a textbox on a form however when using cdo and sending that to a string (which gets html wrapped around it) it won't give me separate lines and instead of seperate paragraphs I get one long string.

    I'd like to be able to add & "<br>" to the end of each line so that it does so when it goes off to email.

    I was thinking a loop/dowith etc to make it happen

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I don't know how important it is for you but I imagine this will take quite a bit of code. I would start by determining the correct char code. Maybe Chr(10)

    Maybe use the instr() function. I have some code that loops through a string for a specific character and returns the position(s) of said character. It is complex code and takes me a while to understand it every time I look at it.

  3. #3
    Petr Danes is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    18
    Not a bit - this is actually quite simple. Use the VBA Replace$ function. Something like (aircode)

    x = Textbox.Value
    x = Replace$(x, vbCr, "<br/>")

    This will replace the return character with the HTML line break command. You may have to experiment a bit, depending on what gives you the line feed in your textbox. It may be return/linefeed combination, in which case use VbCrLf, or just the line feed, in which case use vbLf.

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Petr Danes View Post
    Not a bit - this is actually quite simple. Use the VBA Replace$ function. Something like (aircode)

    x = Textbox.Value
    x = Replace$(x, vbCr, "<br/>")

    This will replace the return character with the HTML line break command. You may have to experiment a bit, depending on what gives you the line feed in your textbox. It may be return/linefeed combination, in which case use VbCrLf, or just the line feed, in which case use vbLf.
    oh I will give that a go - it does pick up the vbCrLf yes?

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    No. You will have to change vbCr with vbCrLf

    x = Replace$(x, vbCrLf, "<br/>")

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by orange View Post
    No. You will have to change vbCr with vbCrLf

    x = Replace$(x, vbCrLf, "<br/>")
    awesome - thanks

  7. #7
    Petr Danes is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    18
    Um, I don't know - I'm going by your description of what is in your textbox. If you have that character in your textbox, then yes, the Replace function will take all instances of that character (or characters - vbCrLf is two) and substitute the text <br/>. You may want to print out the actual ASCII codes in the textbox to be certain of what it contains.

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Works

    Thanks

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

Similar Threads

  1. Unbound Text Box with line break
    By DCV0204 in forum Forms
    Replies: 3
    Last Post: 01-24-2014, 09:32 AM
  2. INSERT INTO from multi line text box
    By Only4Access in forum Forms
    Replies: 3
    Last Post: 01-08-2014, 08:06 PM
  3. Replies: 1
    Last Post: 01-12-2012, 02:54 AM
  4. How to indent first line in text box?
    By JimmD43 in forum Forms
    Replies: 2
    Last Post: 05-08-2011, 01:08 AM
  5. Concatenation of Text and Number
    By diane802 in forum Reports
    Replies: 67
    Last Post: 01-26-2010, 03:37 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