none
problem with char(13) when sending auto-mail RRS feed

  • Question

  • hi guys,

    i have a database recordset, in which there are some records looking like this: abc1abc2abc3

    but when i copy this recor manually and paste in an empty outlook mail, it looks like this:

    abc1

    abc2

    abc3

    coz, i created these records in excel, putting char(13) in between.

    but when it comes to sending thse records via automated mail from access, they still goes like abc1abc2abc3 as oppoed to my expection, which is one under the other.

    as a trick, i tried to create the data like abc1-abc2-abc3 and then tried to replace "-" with char(13) in access vba, but it didn't work.

    how can i manage this, plase hepl.


    Dig your well before you are thirsty

    Friday, February 5, 2016 3:29 PM

Answers

  • Interestingly enough in msgbox, it only requires Chr(10) unless the records are as HTML or something...

    Yes, that's true.  MsgBox() has special logic internally to accept any of CR, LF, or CR+LF as a line break.  However, most of Access doesn't.  If ExcelinEfendisi is using SendObject to send the e-mail, my own tests show that both LF alone and the CR+LF combination work as a line separator, but CR alone doesn't.  Windows applications overall seem to be inconsistent about this.

    Hmm, I may have corrected Imb too soon.  While CR+LF is the standard line-separator for Access, it looks like in SendObject, using LF+CR will work, even though it's nonstandard -- it sees the LF -- Chr(10) -- as a line separator, and ignores the CR.  So for SendObject, the OP could just replace Chr(13) with Chr(10), and it ought to work.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, February 5, 2016 4:47 PM
  • You can try to replace Chr(13) by  Chr(10) & Chr(13).


    You have it reversed, Imb.  It needs to be CR+LF; that is, Chr(13) & Chr(10).

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, February 5, 2016 4:19 PM

All replies

  • but when i copy this recor manually and paste in an empty outlook mail, it looks like this:

    abc1

    abc2

    abc3

    coz, i created these records in excel, putting char(13) in between.

    Hi ExcelinEfendisi,

    You can try to replace Chr(13) by  Chr(10) & Chr(13).

    Imb.

    Correction: The proper order is   Chr(13) & Chr(10), see discussion later on.

    • Proposed as answer by KCDW Friday, February 5, 2016 3:58 PM
    • Edited by Imb-hb Saturday, February 6, 2016 9:49 AM correction
    Friday, February 5, 2016 3:39 PM
  • Hi imb,

    i've already tried all kind of combinations of char(10),char(13),vbcrlf, vbnewline in both excel and access. none works :(


    Dig your well before you are thirsty

    Friday, February 5, 2016 4:18 PM
  • You can try to replace Chr(13) by  Chr(10) & Chr(13).


    You have it reversed, Imb.  It needs to be CR+LF; that is, Chr(13) & Chr(10).

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, February 5, 2016 4:19 PM
  • Interestingly enough in msgbox, it only requires Chr(10) unless the records are as HTML or something...

    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Friday, February 5, 2016 4:25 PM
  • Interestingly enough in msgbox, it only requires Chr(10) unless the records are as HTML or something...

    Yes, that's true.  MsgBox() has special logic internally to accept any of CR, LF, or CR+LF as a line break.  However, most of Access doesn't.  If ExcelinEfendisi is using SendObject to send the e-mail, my own tests show that both LF alone and the CR+LF combination work as a line separator, but CR alone doesn't.  Windows applications overall seem to be inconsistent about this.

    Hmm, I may have corrected Imb too soon.  While CR+LF is the standard line-separator for Access, it looks like in SendObject, using LF+CR will work, even though it's nonstandard -- it sees the LF -- Chr(10) -- as a line separator, and ignores the CR.  So for SendObject, the OP could just replace Chr(13) with Chr(10), and it ought to work.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, February 5, 2016 4:47 PM
  • guys, none works.

    it stil goes one after the other, and looks so messy.



    Dig your well before you are thirsty

    Friday, February 5, 2016 4:58 PM
  • You have it reversed, Imb.  It needs to be CR+LF; that is, Chr(13) & Chr(10).

    Hi Dirk,

    Thank you for this correction, you are right.

    I must have accessed my memory from the wrong direction.

    Imb.

    Friday, February 5, 2016 4:58 PM
  • guys, none works.

    it stil goes one after the other, and looks so messy.


    Could you show us your code, please?  How are you generating the e-mail?  What is the actual value of the field(s) that you are (presumably) putting in the e-mail body?

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, February 5, 2016 5:07 PM
  • Hmm, I may have corrected Imb too soon.  While CR+LF is the standard line-separator for Access, it looks like in SendObject, using LF+CR will work, even though it's nonstandard -- it sees the LF -- Chr(10) -- as a line separator, and ignores the CR.  So for SendObject, the OP could just replace Chr(13) with Chr(10), and it ought to work.

    Hi Dirk,

    Your correction was fully properly. It was not my intention to suggest a non-standard line separator that could work under some special conditions.

    I just meant standard  Chr(13) & Chr(10).

    Imb.

    Friday, February 5, 2016 5:08 PM
  • An alternative to "Chr(13) & chr(10)" is "vbNewLine".
    Saturday, February 6, 2016 12:38 AM
  • In Theory, if you have data in a Table or Query or Datasheet Form and you can select multiple records and copy and paste, then the format is other than plain text format. When you manually paste this into an Outlook email, where your settings under Outlook Options / Mail / Compose Messages / Editor Options / Cut Copy Paste / Pasting From Other Programs = Keep Source Formatting (default), then the result would be

    abc1

    abc2

    abc3

    However, if you are selecting multiple records manually and copying, I don't see how you are pasting them and getting the result in Outlook without a header or the format of the object you copy from. So I would expect to see something like

    <tfoot></tfoot>
    Table1
    aa
    abc1
    abc2
    abc3

    From a single column record of a Table, or from multiple columns

    <tfoot></tfoot>
    Table1
    aa bb cc 11
    a b c 1
    a b c 2
    a b c 3

    unless you choose keep text only in RTF/HTML or choose the format of plain text then you get like the following

    aa           bb           cc           11

    a             b             c             1

    a             b             c             2

    a             b             c             3

    or

    aa

    abc1

    abc2

    abc3

    If your Table fields are storing formatting which I think can only be done in Long Text or Memo Field format then you could use rtf format on the Field(s) and get similar to above results with manual copy/paste. However if the data in the Field in RTF holds the HTML formatting (like <br> and <wbr>) you would probably get something like what you indicated but you would then need to make sure that you code the email in HTML format in the body in order for the format to follow through.

    We would be better able to tell what the issue is if you would share the code you are using to send the email...


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Saturday, February 6, 2016 8:53 AM
  • An alternative to "Chr(13) & chr(10)" is "vbNewLine".

    As is vbCrLf -- but be aware that, while these can be used in VBA code, they cannot be used in queries.

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Saturday, February 6, 2016 10:47 PM
  • thanks evryone,

    i thinked i'd messed up some part of code, so it didn't work.

    now it's ok and works as expected, thanks for your help.


    Dig your well before you are thirsty

    Monday, February 8, 2016 8:31 AM