NotesRichTextRange and FindAndReplace

HiI have developed a mail merging routine, where i make a NotesDocument with some merge fields, and the i replace them with corresponding values from the databases.

I have run into an issue with line breaks, when i replace the merge fields. I use chr$(13) + chr$(10) as line breaks.

I have debugged my code and it seems its this piece of code that removes the line breaks:

(mergeFields and entry are some utility classes we are using that wraps a simple array, so this function essentially just loops all my translated mergefield values)

Public Sub richTextLib_insertMergeFields_richText(rtitem As NotesRichTextItem)

' Now the translated mergefields will be inserted into the RichTextItem

Dim rtrange As NotesRichTextRange

Dim entry As ccEntry

Dim searchStr As String, replaceStr As String



Set rtrange = rtitem.createRange



Set entry = mergeFields.getFirstEntry

Do While Not entry Is Nothing

	searchStr = "[" + entry.getValue("mergefield") + "]"

	replaceStr = entry.getValue("translated")

	

	rtrange.findAndReplace searchStr, replaceStr, RT_FIND_CASEINSENSITIVE + RT_REPL_ALL + RT_REPL_PRESERVECASE

	

	Set entry = mergeFields.getNextEntry

Loop

End Sub

As far as i can tell the line breaks dissapears when i use the rtrange.findAndReplace method.

Is there some workaround or solutions for this?

Kind regards

Jacob

Subject: Code…

I have not experienced a loss of linebreaks, I wrote a similar mail merge function several years ago, and then rewrote it about a year or two ago using RichText classes (after we finally upgraded to ND7). Earlier this year I blooged about it, you can find my code here:http://www.bleedyellow.com/blogs/texasswede/entry/mailmergelotusscript

I am using exactly the same method as you:

cnt = range.FindAndReplace(p.placeholderstring, p.text, 1+4+8+16)

This is towards the end of the code, in the function MergedRichText().