none
Rich Text AppointmentItem Body with VBA automation RRS feed

  • Question

  • I'm trying to create an Appointment Item in Outlook 2013 from Access 2013 using VBA.  The problem is the text from my Access Rich Text Memo Field is not displaying properly in the Outlook Appointment.  The formatting is lost and the markup tags are visible.

    Dim rst as DAO.Recordset
    Set rst = db.OpenRecordSet(TableWithRichTextField)
    Dim olai As Outlook.AppointmentItem
    Set olai = olApp.CreateItem(olAppointmentItem)
    olai.Body = rst!Body 'why is formatting lost?

    The code works fine except for the problem with the Rich Text formatting.

    How do I export Rich Text from Access into Outlook using VBA automation?

    Friday, March 1, 2013 8:06 PM

All replies

  • Set the AppointmentItem.RtfBody property.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Friday, March 1, 2013 8:19 PM
  • still trying.  I found these threads:

    http://msdn.microsoft.com/en-us/library/office/ff861303.aspx

    http://www.pcreview.co.uk/forums/taskitem-and-appointmentitem-formated-body-t2964533.html

    http://www.utteraccess.com/forum/lofiversion/index.php/t1988659.html

    The examples were not very helpful... not sure what I'm trying to do can be done.

    Just to be clear, I create RTF content in an Access Text Box (bound to a RichText Memo field), then I want to send it to Outlook and have the RTF formatting preserved in the Appointment Item Body.  As you know, Outlook AppointmentItem Body is always RTF. 

    I think I need Redemption 5.4...

    Saturday, March 2, 2013 12:10 AM
  • So have you tried to set the AppointmentItem.RtfBody property?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Saturday, March 2, 2013 5:31 AM
  • I tried but I'm not sure how to set it.  The only example I could find was that MSDN article I referenced in my last reply.

    Below is what I tried.  Is this the correct way to set it?  The results I get look like this:

    {\*\generator Riched20 15.0.4454}{\*\mmathPr\mwrapIndent1440 }\viewkind4\uc1

    Dim rst as DAO.Recordset Set rst = db.OpenRecordSet(TableWithRichTextField) Dim olai As Outlook.AppointmentItem Set olai = olApp.CreateItem(olAppointmentItem) olai.Body = rst!Body olai.body = StrConv(olai.RTFBody, vbUnicode)


    • Edited by john1519 Sunday, March 3, 2013 5:15 PM
    Sunday, March 3, 2013 4:49 PM
  • The same way you set the Body property:

    olai.RTFBody = SomeRTFBodyString


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Sunday, March 3, 2013 5:22 PM
  • No luck.

    The error I get is: Error Number -1906245633: The operation failed.

    I tried this:

    olai.RTFBody = "test"

    and received: Error Number -1317601266: Out of memory or system resources.

    MSDN describes it as a read/write prop that returns or sets a byte array.  Am I not setting a byte array?

    Monday, March 4, 2013 7:17 AM
  • you have to create _valid_ RTF text yourself, you cannot set simple text there and expect to be converted for you.
    Monday, March 4, 2013 8:32 AM
  • I created valid RTF in the table field and tried this:

    Dim rst as DAO.Recordset
    Set rst = db.OpenRecordSet(TableWithRichTextField)
    Dim olai As Outlook.AppointmentItem
    Set olai = olApp.CreateItem(olAppointmentItem)
    olai.RTFBody = rst!Body

    Result: Error Number -1906245633: The operation failed.

    As a test, I tried:

    olai.RTFBody = "test"

    not expecting to see RTF, just trying to set the property without error.  But the code still failed with an error.

    If the proper way to set the property is:

    olai.RTFBody = rst!Body

    then the problem is elsewhere, perhaps with Outlook.  There is nothing wrong with the RTF in the table field.  Furthermore, the code works perfectly with plain text.

    Can you get it to work with:

    olai.RTFBody = rst!Body

    I'm still doubtful if setting the property in this way is even possible.


    • Edited by john1519 Monday, March 4, 2013 11:00 AM
    Monday, March 4, 2013 10:58 AM
  • can you paste here value of rst!Body ?
    Monday, March 4, 2013 11:47 AM
  • Firstly, RtfBody property in Outlook Object Model takes a variant array as a parameter, not a string.

    Secondly, "test" is not a valid RTF string.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Monday, March 4, 2013 12:48 PM
  • I tried this:

    olai.RTFBody = Cvar(rst!Body)

    but still received the same error: "The operation failed."

    As for the contents of rst!Body, it is bold, underlined and other formatted text when viewed in the table field.  I'm not sure I can post and exact representation here. If it is sent to olai.Body, the HTML formatting tags are displayed with text.

    Monday, March 4, 2013 10:05 PM
  • html formatting tags? if rst!Body contains formatted html, this is not a valid rtf string. And second, sa Dmitry said - this must be set as byte array, as stated in documentation http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._appointmentitem.rtfbody(v=office.14).aspx
    Tuesday, March 5, 2013 5:11 AM
  • That link you posted had the first example that was helpful.  Can you point me to any other code examples showing how to set a byte array?  I have valid RTF in a table field, the challenge is getting from there into .RTFBody.  Code examples are always the best...  thx.
    Tuesday, March 5, 2013 6:53 AM
  • These forums are for helpful advice.  You should try doing that.
    Tuesday, March 5, 2013 8:05 AM