New to notes, Need help with RTF table

On the 2nd of November I saw that someone had started a post about Rich text tables being created dynamiclly within Notes using LotusScript. I read the article that was posted and tried some of the code but I think I am stuck at the same spot as that poster was. I do not understand how to programmatically tell notes when to end one table and when to start a new table. I looked up the @Midas product and since I am not interested in purchasing, nor needing to purchase at this time, I didnt see the need to try it.

Here is what I am trying to have the script do:

I have a view that is catagorized by managers under which are the different companies they deal with. When a new sale is made or a new company is added it creates a Company Change document. This company change document is then placed within another view which is processed by the Rich Text Table agent to send to the different managers at the end of the month to show their numbers for that month.

Here is the code as I have it right now:

Global Declarations:

Dim db As NotesDatabase

Dim view1 As NotesView

Dim vc As NotesViewEntryCollection

Dim viewc As NotesViewEntry

Dim doc As NotesDocument

Dim maildoc As notesdocument

Dim rtitem As NotesRichTextItem

'Dim entryOne As NotesViewEntry

Dim emailRecipients As Variant

Dim ccemailRecipients As Variant

Dim ModBy As String, ModOn As String, FirmID As String

Dim FieldNames As Variant, OValues As Variant, NValues As Variant

Dim FirmName As String, counter As Integer

Sub Initialize

Dim session As New NotesSession	

Set db = session.CurrentDatabase

Set view1 = db.GetView( "Comp Doc" )	

Set vc = view1.AllEntries 

Set viewc = vc.GetFirstEntry 

Set doc = viewc.Document 

'Set rtitem = doc.GetFirstItem(fc_CommonName)

emailRecipients = doc.manager(0)

ccemailRecipients = doc.subcon(0)			

Set maildoc = New NotesDocument (db)	

maildoc.Form = "Memo"

Set rtitem = maildoc.CreateRichTextItem("Body")



While Not(doc Is Nothing) 

	'create the email document now

	maildoc.SendTo = emailRecipients

	maildoc.CopyTo = ccemailRecipients

	maildoc.Subject = "Monthly Audit Documents"

	Call rtitem.AddNewLine(2)		

	Dim rtsec As NotesRichTextSection 

	

	If doc.Verified(0) <> "Yes" Then

		ModBy = doc.ModBy(0)

		ModOn = doc.ModOn(0)

		Call rtitem.AppendText(ModBy + " - " + ModOn)

		Call rtitem.AddNewline(1)

		FirmName = doc.fc_CommonName(0)

		FirmID = doc.f_uniqueId(0)

		Call rtitem.AppendText(FirmName + " - "	+ FirmID)

		Call rtitem.AddTab (1)

		Call rtitem.AppendDocLink (doc,"Link to Monthly Audit Document")

		Call rtitem.AddNewline(2)	

		Call rtitem.BeginSection(FirmName)

		FieldNames = doc.C_fieldName

		OValues = doc.G_Value

		NValues = doc.V_Value

		counter = Ubound(FieldNames)

		

		Call Table(FieldNames, OValues, NValues, counter)

		

		doc.verified= "Yes"

		Call rtitem.AddNewline (1)

		Call rtitem.EndSection

		Call doc.Save(False, False)

	End If

	

	Set viewc = vc.GetNextEntry(viewc)

	If Not viewc Is Nothing Then

		Set doc = viewc.Document

		emailRecipients = doc.Sales_Rep(0)

		If maildoc.SendTo(0) <> emailRecipients Then

			Call EmailMsg

			Set maildoc = New NotesDocument (db)

			maildoc.Form = "Memo"

			Set rtitem = maildoc.CreateRichTextItem("Body")

		End If			

	Else

		Call EmailMsg	

		Exit Sub

	End If

Wend	

End Sub

Sub Table (FName As Variant, OVal As Variant, NVal As Variant, counter )

Dim session As New NotesSession

Dim ui As New NotesUIWorkspace 

maildoc.Form = "Memo"

Set view1 = db.GetView( "COmp Doc" )	

server = db.Server

dbfilename = db.FilePath	

Dim richStyle As NotesRichTextStyle

Set richStyle = session.CreateRichTextStyle

Set rtnavBody = rtitem.CreateNavigator 



count = counter

For x = 0 To count

	If rtnavBody.findfirstelement(RTELEM_TYPE_TABLE) Then

		Set rtt = rtnavBody.GetElement

		Call rtt.AddRow()

	Else

		Dim Styles(1 To 3) As NotesRichTextParagraphStyle 

		i=1

			'Column 1 holds the FieldName

		Set styles(i) = session.CreateRichTextParagraphStyle 

		styles(i).LeftMargin = RULER_ONE_INCH

		styles(i).FirstLineLeftMargin = 0

		styles(i).RightMargin = RULER_ONE_INCH * 2

		styles(i).Alignment = ALIGN_LEFT

		i=2

			'Column 2 holds the Original Value

		Set styles(i) = session.CreateRichTextParagraphStyle 

		styles(i).LeftMargin = RULER_ONE_INCH

		styles(i).FirstLineLeftMargin = 0

		styles(i).RightMargin = RULER_ONE_INCH * 2

		styles(i).Alignment = ALIGN_LEFT

		i=3

			'Column 3 holds the New Value

		Set styles(i) = session.CreateRichTextParagraphStyle 

		styles(i).LeftMargin = RULER_ONE_INCH

		styles(i).FirstLineLeftMargin = 0

		styles(i).RightMargin = RULER_ONE_INCH * 2

		styles(i).Alignment = ALIGN_LEFT

		Call rtitem.AppendTable (1,3,,,styles)

		Call maildoc.Save(True,True)

		

	'Insert the Column Labels

		Call rtnavBody.FindNthElement(RTELEM_TYPE_TABLECELL,1)

		Call rtitem.BeginInsert (rtnavBody)

		richStyle.Bold = True

		Call rtitem.AppendStyle (richStyle)

		Call rtitem.AppendText (" Comp Name")

		richStyle.Bold = False

		Call rtitem.AppendStyle (richStyle)

		Call rtitem.EndInsert 

		Call rtnavBody.FindNextElement(RTELEM_TYPE_TABLECELL)

		Call rtitem.BeginInsert (rtnavBody)

		richStyle.Bold = True

		Call rtitem.AppendStyle (richStyle)

		Call rtitem.AppendText (" Original Value")

		richStyle.Bold = False

		Call rtitem.AppendStyle (richStyle)

		Call rtitem.EndInsert 

		Call rtnavBody.FindNextElement(RTELEM_TYPE_TABLECELL)

		Call rtitem.BeginInsert (rtnavBody)

		richStyle.Bold = True

		Call rtitem.AppendStyle (richStyle)

		Call rtitem.AppendText (" New Value")

		richStyle.Bold = False

		Call rtitem.AppendStyle (richStyle)

		Call rtitem.EndInsert 

		

		Call rtnavBody.FindFirstElement(RTELEM_TYPE_TABLE)

		Set rtt = rtnavBody.GetElement

		Call rtt.AddRow()

		Call maildoc.Save(True,True)

	End If

	

'write the data into the tablecells

	rc% = rtt.Rowcount

	cc% = rtt.ColumnCount

	rcc% = rc% * cc%

	cl% = rcc% -2

	

	Call rtnavBody.FindNthElement(RTELEM_TYPE_TABLECELL,cl%)

	'Call rtnavBody.FindNextElement(RTELEM_TYPE_TABLECELL)

	Call rtitem.BeginInsert (rtnavBody)

	Call rtitem.AppendText(CName(x))

	Call rtitem.EndInsert 

	

	Call rtnavBody.FindNextElement(RTELEM_TYPE_TABLECELL)

	Call rtitem.BeginInsert (rtnavBody)

	Call rtitem.AppendText(OVal(x))

	Call rtitem.EndInsert 

	

	Call rtnavBody.FindNextElement(RTELEM_TYPE_TABLECELL)

	Call rtitem.BeginInsert (rtnavBody)

	Call rtitem.AppendText(NVal(x))

	Call rtitem.EndInsert 

	'x=x+1

Next

'Alternate row colors

rtt.Style = TABLESTYLE_ALTERNATINGROWS

Dim color As NotesColorObject 

Dim color2 As NotesColorObject 

Set color = session.CreateColorObject 

Set color2 = session.CreateColorObject 

color2.NotesColor = COLOR_GREEN

color.NotesColor = COLOR_WHITE

Call rtt.SetColor(Color2)

Call rtt.SetAlternateColor(Color)



Call maildoc.Save(True,True)

End Sub

Sub EmailMsg

Call rtitem.AppendText ("Thank you,")

Call rtitem.AddNewLine(1)

Call rtitem.AppendText ("The Management")

Call maildoc.Send(False)

End Sub

Thanks in advance if you can help me.

Jonus