NotesRichTextItem.AppendStyle() does not work

My agent loops thru some “products”, each of which has “posts”. It generates an email containing the data. It formats a rich-text field using a NotesRichTextItem (named “Body”) and some NotesRichtextStyle objects. The only thing that is wrong is that the formatting of the Body field does not obey the styles used.

I am testing the agent on my client, Designer 6.5 from September 26, 2003.

'Loop over Products

Forall prod In aOneUsersProducts

If ProductHasNewDocs( prod ) Then

aDocs = DocDataByProduct( prod )		

Call rtitem.AppendStyle( rtsHel12Red )

Call rtitem.AppendText( "New Posts for Product: " & prod  & Chr(13) & Chr(13) )

Call rtitem.AppendStyle( rtsHel10Black )

' Loop over the posts

For ix = 1 To Ubound( aDocs, 2 )

  Call rtitem.AppendText( "Subject: " & aDocs( conSUBJECT, ix) & Chr(13) )

  Call rtitem.AppendText( "Posted by: " & aDocs( conAUTHOR, ix) & Chr(13) & Chr(13) )

Next

End If

End Forall

Clearly the “New Posts for Product” lines should display in 12-point Red Helvetica, while the “Subject” and “Posted By” lines should be in 10-point Black Helvetica .

Instead, the first “New Posts for Product” line is correctly formatted in 12-point Red Helvetica. All the rest of the lines are in 10-point Black Helvetica .

I have tried the suggestions I found in this forum including:

– add a space with .AppendText( " " ) and then call .AppendStyle() again.

– Reset the NotesRichtextStyle objects to Nothing and recreate them before the .AppendStyle() .

These ideas did not work. Also, I tried creating a new (temp) RichTextItem, then appending the style and the text to the temp RTI, then appending that entire item to the Body RTI. That doesn’t work either.

Any other ideas?

The NotesRichtextStyle object variables are global and are set with this subroutine:

Sub SetupStyles

Set rtsHel14Red = Nothing

Set rtsHel14Red = S.CreateRichTextStyle

With rtsHel14Red

.NotesFont = FONT_HELV

.FontSize = 14

.NotesColor = COLOR_RED

.Bold = True

.Underline = False

End With

Set rtsHel12Red = Nothing

Set rtsHel12Red = S.CreateRichTextStyle

With rtsHel14Red

.NotesFont = FONT_HELV

.FontSize = 12

.NotesColor = COLOR_RED

.Bold = True

.Underline = False

End With

Set rtsHel10Black = Nothing

Set rtsHel10Black = S.CreateRichTextStyle

With rtsHel10Black

.NotesFont = FONT_HELV

.FontSize = 10

.NotesColor = COLOR_BLACK

.Bold = True

.Underline = True

End With

End Sub

Calling this subroutine before each AppendStyle() does not help.

Subject: NotesRichTextItem.AppendStyle() does not work

Rich,

Maybe you need to reset values to false before setting them to something new as in this example…

Dim s As New NotesSession, db As NotesDatabase, doc As NotesDocument

Dim rtBody As NotesRichTextItem, rtStyle As NotesRichTextStyle

Set db = s.CurrentDatabase

Set doc = db.CreateDocument

Set rtBody = New NotesRichTextItem(doc, “Body”)

Set rtStyle = s.CreateRichTextStyle

rtStyle.Bold = True

Call rtBody.AppendStyle(rtStyle)

Call rtBody.AppendText({New Posts for Product: … etc.})

rtStyle.Bold = False

Call rtBody.AppendStyle(rtStyle)

Also, nowhere do I see a…

Dim rtsHel14Red As NotesRichTextStyle, rtsHel12Red As NotesRichTextStyle, rtsHel10Black As NotesRichTextStyle

…line.

Ken

Subject: RE: NotesRichTextItem.AppendStyle() does not work

The DIM statements are in the Declarations code. It uses Option Public, so these variables are global.

I will try your suggestion. Unlike most of the postings here, this agent has multiple NotesRichtextStyle objects. Each one is initialized once, and its properties never change again. I like this approach better for readability but I am willing to switch if the other way will actually work …

Subject: RE: NotesRichTextItem.AppendStyle() does not work

I’m confused. You say:"… the ‘New Posts for Product’ lines should display in 12-point Red Helvetica, while the ‘Subject’ and ‘Posted By’ lines should be in 10-point Black Helvetica.

Instead, the first “New Posts for Product” line is correctly formatted in 12-point Red Helvetica. All the rest of the lines are in 10-point Black Helvetica."

How is this different from what you said you wanted?

Subject: RE: NotesRichTextItem.AppendStyle() does not work

What I mean is, the first set comes out correct, a red heading and black details. But the rest of the headings aren’t red nor bold; they and the details are all the same font.

Subject: RE: NotesRichTextItem.AppendStyle() does not work

A strategically placed call to Update might help. Note also it’s a bad idea to use chr$(13) for all your line breaks. AddNewLine to create a new paragraph is the preferred method.

Are you really using All Releases, or is there a specific version where you have this problem?

Subject: RE: NotesRichTextItem.AppendStyle() does not work

Thanks for the ideas. I have switched to using AddNewLine(), and the agent calls Update() now, but the results are the same.

I am developing and testing the agent on my client, Designer 6.5 from September 26, 2003. The database itself sits on an R6.5 server .