Importing contents from a RichTextBox in VB to Lotus RichTextItem

Hi Everyone,

I am developing an application in VB that will add a new appointment document to a user’s lotus notes mail file. The VB application allows the user to add text to the body of the appointment using a rich text box on the VB form. I have the code written to add the appointment but when I append the text from the RichText box, it list the RichText coding and not the text with the correct formatting.

Does anyone know how to append richtext from a VB RTF box to lotus notes?

Here is a copy of my code:

Public Function AddCalEntry(UserName As String, UserPass As String, ByRef Subject As String, Body As RichTextBox, _

ApptDate As String, StartTime As Date, MinsDuration As Integer) As String



Dim MailDbName As String, strSTime As String, strETime As String



Dim MySession As New NotesSession

Dim NotesDB As NotesDatabase

Dim MyVW As NotesView

Dim CalenDoc As NotesDocument

Dim MyItem As NotesItem

Dim MyDocColl As NotesDocumentCollection

Dim RichTextItem As NotesRichTextItem



If Not UserPass = "~" Then

    Call MySession.Initialize(UserPass)

Else

    Call MySession.Initialize

End If



MailDbName = UserName + ".nsf"

Set NotesDB = MySession.GetDatabase(ServerName, MailDbName, False)



If Not NotesDB.IsOpen Then Exit Function

'On Error GoTo SendNotesErr

strSTime = CStr(FormatDateTime(StartTime, vbShortTime))

strETime = CStr(FormatDateTime(DateAdd("n", MinsDuration, StartTime), vbShortTime))



Set CalenDoc = NotesDB.CreateDocument

    CalenDoc.ReplaceItemValue "Form", "Appointment"

    CalenDoc.ReplaceItemValue "AppointmentType", "0"

    CalenDoc.ReplaceItemValue "STARTDATETIME", CDate(ApptDate & " " & strSTime)

    CalenDoc.ReplaceItemValue "CALENDARDATETIME", CDate(ApptDate & " " & strSTime)

    CalenDoc.ReplaceItemValue "EndDateTime", CDate(ApptDate & " " & strETime)

    CalenDoc.ReplaceItemValue "Subject", Subject

    

    Set RichTextItem = CalenDoc.CreateRichTextItem("Body")

    Call RichTextItem.AppendText(Body.TextRTF)

    

    CalenDoc.ReplaceItemValue "MeetingType", 1

    CalenDoc.ReplaceItemValue "$Alarm", 1

    CalenDoc.ReplaceItemValue "$AlarmOffset", -20

    CalenDoc.ReplaceItemValue "$PublicAccess", "1"

    CalenDoc.ReplaceItemValue "_ViewIcon", 160

    CalenDoc.ReplaceItemValue "$CSVersion", 2

    CalenDoc.ReplaceItemValue "$BusyName", MySession.UserName

    CalenDoc.ReplaceItemValue "$BusyPriority", "1"   'Show Busy = 1; Show Not Busy = 2

    CalenDoc.ReplaceItemValue "BookFreeTime", "1"   'Not Checked = ""; Checked = "1"

    CalenDoc.ReplaceItemValue "CHAIR", MySession.UserName

    CalenDoc.ReplaceItemValue "ORGTABLE", "C0"

    CalenDoc.ReplaceItemValue "ExcludeFromView", "D"

    CalenDoc.ReplaceItemValue "Principal", MySession.UserName



CalenDoc.ComputeWithForm True, False

CalenDoc.Save True, False

SendNewNotesAppointment = CalenDoc.GetItemValue("ApptUNID")(0)



'myFrm.MousePointer = vbDefault



Exit Function

SendNotesErr:

SendNewNotesAppointment = False

End Function

Subject: Importing contents from a RichTextBox in VB to Lotus RichTextItem

You’d need to use the “.Text” property instead of the “.TextRTF”.

Subject: RE: Importing contents from a RichTextBox in VB to Lotus RichTextItem

Thanks for your reply. It worked pretty good, but it only moved over the text and not the formating. I was hoping to carry over the formatting along with the text.

Is there a way to copy it to the clipboard and then re-paste the text and the formatting into the RichTextItem?

Subject: RE: Importing contents from a RichTextBox in VB to Lotus RichTextItem

Not without opening the Notes document to the UI. You could spend time parsing the RTF content of the RichTextBox and translating that to calls to the various NotesRichText constructs (styles, paragraph styles, and so on), but that’s a bit much for a calendar entry, isn’t it?

Subject: RE: Importing contents from a RichTextBox in VB to Lotus RichTextItem

Well you are right, that is a little too much for a simple calendar entry. I will just have to live with out the formatting.

Thanks for your assistance.