Results 1 to 13 of 13
  1. #1
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67

    Adding vbnewline to a text string

    I have a bound textbox where I've set ENTER KEY BEHAVIOR as "New Line in Field" and that works great. Upon hitting ENTER, it takes you to a new line and stores the text, stacked upon one another in the table like
    text 1
    text 2
    text 3


    but when I view this field in the LOCAL WINDOW it shows it as 1 one long string.
    Does New Line in Field establish CHR$(10) and CHR$(13) properties?
    I'm send this string to OUTLOOK and I need it t appear as stacked as well. How can I accomplish this?

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Ctl-Enter

    or in vb: vbCRLF

  3. #3
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I just tested with this procedure and its showing chr(13) & chr(10)

    Code:
    Public Sub sChkNonPrint(strCheck)
        Dim lngLoop As Long
     
        For lngLoop = 1 To Len(strCheck)
            Debug.Print Mid(strCheck, lngLoop, 1) & ": " & Asc(Mid(strCheck, lngLoop, 1))
        Next lngLoop
        
    End Sub

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    10 and 13 are just ascii values for new line and carriage return. They can be employed together with the vb constant vbCrLf.
    AFAIK, the setting "new line in field" is supposed to replace the need to use Ctrl+Enter. I'm thinking you need to disregard what you see in the locals window and check the table field instead. Make sure you expand the table record height when checking.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    How are you sending data to Outlook email?

    I did test. I see multiple lines in Immediate Window.

    Chr(13) & Chr(10), vbCrLr, NewLineInField carry through for SendObject as well as .Body (but not .HTMLBody) when using Outlook objects to create email.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Quote Originally Posted by June7 View Post
    How are you sending data to Outlook email?

    I did a test. Chr(13) & Chr(10), vbCrLr, NewLineInField carry through for SendObject as well as .Body (but not .HTMLBody) when using Outlook objects to create email.
    In my humble estimation, there's no indication that he got that far.
    but when I view this field in the LOCAL WINDOW it shows it as 1 one long string.
    I guess we'll have to wait to find out.
    EDIT:
    I'm presuming he meant "Locals Window" but no, I didn't test to see how line wrapped values are displayed there. I would bet that non printable characters are ignored.

  7. #7
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67
    I'm still a bit confused upon checking what you all have suggested. The Immediate Window did show multiple line and yes, the table record height is set; illustrating multiple lines as well. Here's a snippet of my code:

    Dim Question as String
    If Not Null(Me!InfoQuestion) Then
    Question = Me!InfoQuestion
    Debug.Print Question ----> DOES show multiple line in Immediate, but Locals shows it as "line1 line2 line3", which truly might be OK just because it can only present it this way, Continued at A:
    Else
    Question = ""
    End If

    Call Distribute(Question)


    Public Sub Distribute(Question as String)
    Set OutApp = Create("Outlook Application")
    Set OutMail = OutApp.CreateItem(olMaitItem)

    A:
    BUT, when passing QUESTION to Outlook, this field is showing it as
    "line1 line2 line3" where it's not retaining the vbCrLf characteristics.
    Should it be?

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I was only ever able to wrap lines when 'exporting' to Outlook by building the body as html. That was good in that I was able to control font characteristics as well, but if memory serves, others here have reported that it's not necessary. I look forward to a reminder of how else it can be done, assuming it can be. Maybe it's a function of controlling the message body type at the start (plain text vs rich text vs html)?

    I've read that there is an Outlook option to 'never remove line breaks from plain text' or something like that. Perhaps your message is being constructed as plain text?

    EDIT
    There are at least 3 solutions posted here. Watch out for the ones that only apply to jscript
    https://stackoverflow.com/questions/...he-line-breaks

  9. #9
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67
    The message is being created in html since I'm using .HTMLBody to create the body of the email.

  10. #10
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    HTML automatically strips out certain types of acsii line breaks - from memory you have to insert a <br> line break instead.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  11. #11
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67
    Upon playing around with this, by changing .HTLMBody to just .Body, was I able to get that field to display as multiple line. So, knowing this, can you interchange using both .HTLMBody and .Body to create your body? It seems if I use both, it wipes out the other.

    .HTMLBody =
    .Body =
    .HTMLBody =

    What other choices are there besides these 2?
    Suggestions!

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    If you want to use .HTMLBody, replace Chr(13) & Chr(10) with <br>:

    Replace([fieldname], Chr(13) & Chr(10), "<br>")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Don't know if any of this will help, but here's the gist of what I did. I was using COM to communicate with the mail server but Outlook to build and send the message. The first part builds the standard opening line complete with 2 line wraps:

    strBody = "<P>The following requisitions may require your attention:</P><P>"

    I wanted to control positioning without trying to populate table cells, hence the spaces:
    spcs = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"

    Other code got the values from a recordset that were pertinent to a particular user:
    svLine = svReqNo & spcs & svStatus & spcs & svStatusDate & spcs & svRBD & spcs
    svLine = svLine & svPO & "<BR>" & svCmnt & "<BR><BR>"

    Now concatenate the 1st and 2nd parts:
    strBody = strBody & svLine

    This part built the email header section like any web page:
    htmHead = "<HTML><HEAD><META HTTP-EQUIV=3D" & Chr(34) & "CONTENT=3D"
    htmHead = htmHead & Chr(34) & "text/html; = charset=3DISO-8859-1" & Chr(34) & ">"
    htmHead = htmHead & "</HEAD>"

    Set up the body font (can't recall what "2" was for:
    htmBody = "<body><font face=" & Chr(34) & "Arial" & Chr(34) & " size=" & Chr(34)
    htmBody = htmBody & "2" & Chr(34) & ">"

    Build the closing tag:
    htmClose = "</P></font></body></HTML>"

    Prior to here, the code is partial and doesn't include parts that aren't relevant to the issue at hand. Then the assembled body gets passed to the pSendMail function in order to create an email for a specific user. After that, the calling function looped on to the next user and repeated the pSendMail call.

    With objMsg
    .FROM =
    .To =
    .subject =
    .HTMLBody = htmHead & htmBody & eml.itemBody & htmClose
    .Send
    End With

    That's about it.

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

Similar Threads

  1. Replies: 5
    Last Post: 02-20-2018, 07:25 PM
  2. Replies: 3
    Last Post: 08-04-2017, 08:28 AM
  3. Replies: 2
    Last Post: 01-10-2016, 06:47 PM
  4. Replies: 6
    Last Post: 05-29-2015, 10:21 AM
  5. Adding textbox.text to a string variable...
    By MatthewGrace in forum Programming
    Replies: 2
    Last Post: 05-20-2014, 11:43 AM

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