Adding rows to a table - RTF problem

Hi all,

Hope somebody can help me.

I’m trying to add rows to a table in a rich text field without success.

This field - called History - is not in a table in the form (although it is inside a section).

When the doc is created, the code runs fine, creating the table with one line, one row and the text inside the cell. The problem happens when I edit the same document and try to save the change in the history field. It seems that Notes does not “see” the table anymore (the message “No table” is displayed)

If someone can help me, it would be great. The code is below.

TIA,

Renan.

Sub Queryclose(Source As Notesuidocument, Continue As Variant)

If msg <> “” Then

Dim doc_back As NotesDocument

Set doc_back = Source.Document

Call GenerateTable(doc_back)

End If

End Sub

Globals myForm ’ Sub declared in the Globals

Sub GenerateTable(doc As NotesDocument)

Dim rtnav As NotesRichTextNavigator

Dim rtt As NotesRichTextTable

Dim rtitem As NotesRichTextItem

Dim history As String

Dim dateStr As String

Dim cnUser As String

Dim abbUser As Variant

dateStr = Format(Now, “mm-dd-yyyy”)

cnUser = doc.UserName(0)

abbUser = Evaluate(|@Name([Abbreviate]; “| + cnUser +|”)|)

If msg = “New Document” Then

history = "Document created on " + dateStr + Space(2) + "by " + abbUser(0)

Set rtitem = doc.GetFirstItem(“History”)

Call rtitem.AppendTable(1, 1)

Set rtnav = rtitem.CreateNavigator

Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)

Call rtitem.BeginInsert(rtnav)

Call rtitem.AppendText(history)

Call rtitem.EndInsert

Call doc.Save(True, False)

Exit Sub

Else

history = "Review on " + dateStr + " by " + abbUser(0)

End If

Set rtitem = doc.GetFirstItem(“History”)

Set rtnav = rtitem.CreateNavigator

Call rtnav.FindFirstElement(RTELEM_TYPE_TABLE)

If Not rtnav.FindFirstElement(RTELEM_TYPE_TABLE) Then

Messagebox “No table”

Exit Sub

End If

Set rtt = rtnav.GetElement

Call rtt.AddRow

Call rtnav.FindNextElement(RTELEM_TYPE_CELL)

Call rtitem.BeginInsert(rtnav)

Call rtitem.AppendText(history)

Call rtitem.EndInsert

Call doc.Save(True, False)

End Sub

Subject: Adding rows to a table - RTF problem

Hi Brandt and Ben,

Thanks for answering.

Yeah, Brandt, you were right. I changed RTELEM_TYPE_CELL to RTELEM_TYPE_TABLECELL and it worked…

And it works if the field is editable.

Now, I noticed that if I leave the RTF as computed, the table is created, but it cannot be accessed anymore (the message No table - see code - is displayed).

Meanwhile, I’m using the following workaround, available in this forum:

"Leave the rich text field as editable,

deselect the field property “Show Field Delimiters”

and put a line of code in the “Entering” field event,

Call UIDoc.GotoPrevField"

It works, but does anybody know if a solution has been found?

Subject: Adding rows to a table - RTF problem

Renan,

I believe that even when you declare a NotesRichTextItem object and set it equal to your field using NotesDocument.GetFirstItem, you still need to test to see if it is actually a richtext item before being able to use the NotesRichTextItem methods and properties. If that is the case (and it looks that way in the documentation) then you would need to encase your table generation in this line:

If (rtitem.Type = RICHTEXT) then

…table generating code.

End If

hth.

brandt

Subject: RE: Adding rows to a table - RTF problem

Hi Brandt,

Thanks for your suggestion, but the problem remains.

Any other idea?

Renan

Subject: RE: Adding rows to a table - RTF problem

Renan,

Just looked at your first post again, and noticed that you are not calling the RTELEM_TYPE_TABLECELL correctly in the part of your script that operates on an existing table. There is no such constant as RTELEM_TYPE_CELL. So that may be one reason.

A question though…is your value always going to be a text string? if so, I may have a better solution for you that doesn’t involve generating a table…

brandt

Subject: Adding rows to a table - RTF problem

It certainly sounds like the rich text classes think that the table is inside another table. Not sure what is making that happen, but if you look with NotesPeek or something similar, I think you will find the table tags have been converted to nested table tags, which the standard rich text classes can’t handle.