Creating rich text table in current document

I am creating a travel/vacation db- the vacation part works flawlessly- I am attempting to dynamically create a table in the existing (on screen) document that will have as many rows as there are days in the field “DateRange”. I took the code from the help database where, in fact, it works from a view button. I have modified it to a button on the form after the field DateRange. The debugger shows no errors- but the table doesn’t show- if I save and close and reopen it- it still doesn’t show. At the moment, I just want it to make the table w/ the right number of rows (The date range field works off of a StartDate & EndDate field which explodes the dates inbetween) I know I am missing something simple-- the commented out lines were the original attempt-

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Set db = session.CurrentDatabase

REM Create document with Body rich text item

'dim doc As New NotesDocument(db)

Dim uidoc As NotesUIDocument

Set uidoc = ws.CurrentDocument

Dim Doc As NotesDocument

Set Doc = uidoc.Document

Dim Body As String

			'Dim RTItem As NotesRichTextItem

Set richbody = New NotesRichTextItem(Doc,"body")

'Dim Body As New NotesRichTextItem(doc, "Body")

  REM Create table in Body item

Dim MyRowCount As Variant

MyRowCount=doc.DateRange

Dim GetRowCount As Integer

GetRowCount = Ubound(MyRowCount) + 1

rowCount% = GetRowCount

columnCount% = 3

Call Richbody.AppendTable(rowCount%, columnCount%)

REM Populate table

Dim rtnav As NotesRichTextNavigator

Set rtnav = Richbody.CreateNavigator

Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL) 

For iRow% = 1 To 4 Step 1

	For iColumn% = 1 To 3 Step 1

		Call Richbody.BeginInsert(rtnav)

		Call Richbody.AppendText("Row " & iRow% & ", Column " & iColumn%)

		Call Richbody.EndInsert

		Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

	Next

Next

Call doc.Save(True,True)

TIA

Tom

Subject: Creating rich text table in current document

The first thing I noticed is that you are creating a new rich text item. You should use Doc.GetFirstItem(“Body”) to get a handle to the existing RichTextItem instead. After making that change I was able to get the table to create but it was only visible if I closed the UI Document without saving and then reopened the document.

I’m still working with it to see if I can convince the UIDoc to refresh otherwise I’ll post the code to close the UIDoc and then reopen it.

Subject: RE: Creating rich text table in current document

Here is the code that I was able to make work. I added a failover for the richtextitem on the off chance that it doesn’t already exist in the document. You can prevent the UIDoc from prompting to save by adding a SaveOptions field to the form and setting it to “0”.

Sub Click(Source As Button)

'Dim all variables at once to make the code easier to read

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim uidoc As NotesUIDocument

Dim Doc As NotesDocument

Dim Body As String

Dim RTItem As NotesRichTextItem

Dim MyRowCount As Variant

Dim GetRowCount As Integer

’ Get handles to the required objects

Set db = session.CurrentDatabase

Set uidoc = ws.CurrentDocument

Set Doc = uidoc.Document

'Save & Close the UI Doc

Call uidoc.Close(True)

'Set handle to Rich Text Item and add the table

Set RTItem = Doc.GetFirstItem("Body")

If RTITem Is Nothing Then

   Set RTItem = Doc.CreateRichTextItem("Body")

End If



MyRowCount=doc.Days

GetRowCount = Ubound(MyRowCount) + 1

rowCount% = GetRowCount

columnCount% = 3

Call RTItem.AppendTable(rowCount%, columnCount%)

'Save the document

Call doc.Save(True,True)

'reopen the document in edit mode

Call WS.EditDocument(True, Doc)

End Sub

Subject: RE: Creating rich text table in current document

Thanks Shawn. That is a huge help- now I start getting it to build a field for each date in the range- hopefully I can handle that.Tom