Get current table in RTF item

Hi all,

My form has a RTF item called “Body”.

I’ve created two button actions for this form:

  1. Add Tabbed Table

  2. Add Tab

The first action works fine and the second one, “almost”.

The problem arises when I create more than one table in the Body field and I try to add more rows (tabs) to the second (or third, or fourth, or so on) table.

For instance, I press the “Add Tabbed Table” twice and that will create two tabbed tables in the form with one tab each.

Next I press the “Add Tab” and that will add a new tab to the second table. If I press it again, it’ll create another tab to the second table.

What I’d like to do is (using this example): click anywhere inside the first table and then press the “Add Tab” button. That would add another tab in the FIRST table (this is what happens if I go to the menu option Table and select Append Row). But I’m trying to do that by code, to make the life easier to the user, you know what I mean?

Below is the code behind the “Add Tab” button action.
Note: I added (and commented) the line Set rtt = rtnav.GetNthElement(RTELEM_TYPE_TABLE, 1) that does exactly what I want in my example.

Could anybody give me some advice?

Thanks in advance,

Renan

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument, uidocNew As NotesUIDocument

Dim rti As NotesRichTextItem

Dim rtnav As NotesRichTextNavigator

Dim rtt As NotesRichTextTable

Set uidoc = ws.CurrentDocument

Call uidoc.Refresh(True)    ' do this to get the Body field in UI

Set doc = uidoc.Document

Set rti = doc.GetFirstItem("Body")

Set rtnav = rti.CreateNavigator

If rtnav.FindFirstElement(RTELEM_TYPE_TABLE) Then

	count% = 0

	Do

	count% = count% + 1

	Loop While rtnav.FindNextElement

Else

	Messagebox "Body item does not contain a table", 0+16, "Message"

	Exit Sub

End If

If count% = 1 Then

	Messagebox "One table only"

Else

	Messagebox "More than one table"

End If

’ Set rtt = rtnav.GetNthElement(RTELEM_TYPE_TABLE, 1) => commented!!!

Set rtt = rtnav.GetElement

Call rtt.AddRow(1)

Call doc.ComputeWithForm(True, False)   ' without this command, RTF is not updated

doc.SaveOptions = "0"  'make it possible to close the document without a "do you want to save" prompt

Call uidoc.Close(True)  

Set uidocNew = ws.EditDocument(True, doc, , , , True)

Delete uidoc

uidocNew.Document.RemoveItem("SaveOptions")  'remove the SaveOptions field...

End Sub

Subject: Get current table in RTF item

The problem is that the code you are using works on the back end RTItem and cannot be aware of where the cursor is in the front-end rich text editor. You’d need to use @Command([EditTableInsertRowColumn]) to work from the UI (without visiting the C API, at least), and all that does is open the insert dialog if the cursor’s in a table.