Rich Text on the web stumper

Here is one that has me stumped. I have an agent that generates a report via rich text that I call on webquerysave event of a report selection form. This code fails when it tries to append a table using a rich text paragraph style. The log.nsf says Missing RichTextParagraphStyle object. I use this richtextparagraph syle for another table prior to this table that fails to append without error. I then moved the code that defines the table before each append table statement in an effort to debug. No luck. This code runs in the notesclient fine when I hard code the key$ in the following code:

Dim session As New NotesSession

Dim db As NotesDatabase

Set db=session.CurrentDatabase

Dim doc As NotesDocument

Dim doc2 As NotesDocument	

Dim doc3 As NotesDocument

Dim doc4 As NotesDocument

Dim rtitem As NotesRichTextItem

Dim rtnav As NotesRichTextNavigator

Dim rtt As NotesRichTextTable

Dim view As NotesView

Dim view2 As NotesView

Dim view3 As NotesView

Dim view4 As NotesView

Dim vec As NotesViewEntryCollection

Dim vec2 As NotesViewEntryCollection

Dim vec4 As NotesViewEntryCollection

Dim entry As NotesViewEntry

Dim entry2 As NotesViewEntry

Dim entry4 As NotesViewEntry

Dim linecount As Integer

Dim pagecount As Integer

Dim pytotal As Integer

Dim custpytotal As Integer

Dim pygrandtotal As Integer

Dim cytotal As Integer

Dim custcytotal As Integer

Dim cygrandtotal As Integer

Dim custjointtotal As Integer

Dim custtotaldue As Double

Dim qtytotal As Integer

pytotal=0

custpytotal=0

pygrandtotal=0

cytotal=0

custcytotal=0

cygrandtotal=0

custjointtotal=0

custtotaldue=0

qtytotal=0

pagecount=1

linecount=0





Dim rtpStyle As NoptesRichTextParagraphStyle	

Dim rtps(1 To 6) As NotesRichTextParagraphStyle



Dim rtpStyle2 As NotesRichTextParagraphStyle	

Dim rtps2(1 To 2) As NotesRichTextParagraphStyle



Dim rtpStyle3 As NotesRichTextParagraphStyle	

Dim rtps3(1 To 4) As NotesRichTextParagraphStyle



Set view=db.GetView("(SeedReps)")

Set view2=db.GetView("(CYOrders2)")

Set view3=db.GetView("(PYDeliveryReceipts2)")

Set view4=db.GetView("(LUSubs)")



'Set doc=session.DocumentContext

’ key$=doc.SeedRep(0)

key$="11-119"



Set reportdoc=New NotesDocument(db)

reportdoc.Form="SeedRepReport"

Set rtitem=reportdoc.CreateRichTextItem("Body")

Call rtitem.AppendText(Cstr(Today))

Call rtitem.AddTab(3)

Call rtitem.AppendText("Wyffels Hybrids, Inc.")

Call rtitem.AddTab(2)

Call rtitem.AppendText("Page"+Cstr(pagecount))

Call rtitem.AddNewLine(1)

linecount=linecount+1

Call rtitem.AddTab(2)

Call rtitem.AppendText("2003 Seed Rep Activity Report")

Call rtitem.AddNewline(1)

linecount=linecount+1

Call rtitem.AddTab(3)

’ Call rtitem.AppendText(key$+" "+doc.SeedRep(0))

Call rtitem.AppendText(key$+"   "+"Todd Syata")

Call rtitem.AddNewline(1)

linecount=linecount+1

Call rtitem.AppendText("=================================================================================")

Call rtitem.AddNewline(1)	

linecount=linecount+1



Set vec=view.GetAllEntriesByKey(key$,True)



For i=1 To vec.Count ' customers

	Set entry=vec.GetNthEntry(i)

	Set doc2=entry.Document

	

	'add code here for tracking each sub separately, sort in view

	' also add  running total for customer for all subs

	

	' write out info from this form

	Call rtitem.EndInsert

	Call rtitem.AddNewLine(2)	

	Call rtitem.AppendText(doc2.DMNAME(0))

	Call rtitem.AddNewLine(1)	

	linecount=linecount+1

	Call rtitem.AppendText(doc2.DMCITY(0))

	Call rtitem.AddNewLine(1)	

	linecount=linecount+1

	Call rtitem.AppendText(doc2.DMPHNA(0)+"-"+doc2.DMPHN1(0)+"-"+doc2.DMPHN2(0))

	Call rtitem.AddNewLine(2)	

	linecount=linecount+1

	

	Set vec4=view4.GetAllEntriesByKey(doc2.DMCUST(0),True)

	

	For k= 1 To vec4.Count  ' subs

		

		Set entry4=vec4.GetNthEntry(k)

		Set doc4=entry4.Document

		subnum$=Cstr(doc4.DMSUB(0))

		

		key2$=Cstr(doc2.DMCUST(0))+"-"+subnum$

		Set vec2=view2.GetAllEntriesByKey(key2$,True)

		

' write out sub num here

		If Len(subnum$)=1 Then

			subdisplay$="00"+subnum$

		Elseif Len(subnum$)=2 Then

			subdisplay$="0"+subnum$

		Else

			subdisplay$=subnum$

		End If

		

		Call rtitem.AppendText(Cstr(doc2.DMCUST(0))+"-"+subdisplay$)

		Call rtitem.AddNewLine(1)	

		linecount=linecount+1

		

		If vec2.Count=0 Then

			Call rtitem.AppendText("No orders for current year.")

			Call rtitem.AddNewLine(1)	

			linecount=linecount+1

		Else

			Call rtitem.AppendText("Current Year Orders")

			Call rtitem.AddNewline(1)

			

			For column = 1 To 6

				Set rtpStyle = session.CreateRichTextParagraphStyle 

				

				If column = 6 Then

					rtpStyle.RightMargin = RULER_ONE_INCH * .75

					rtpStyle.FirstLineLeftMargin = 0

					rtpStyle.LeftMargin = 0

					rtpStyle.ALIGNMENT=ALIGN_RIGHT

				Else

					rtpStyle.RightMargin = RULER_ONE_INCH * .75

					rtpStyle.FirstLineLeftMargin = 0

					rtpStyle.LeftMargin = 0

					rtpStyle.ALIGNMENT=ALIGN_LEFT

				End If

				

				Set rtps(column) = rtpStyle

			Next

			

		' build cy order table		

			Call rtitem.AppendTable(1,6,"",RULER_ONE_INCH,rtps)

					' save doc Y/N?

			Set rtnav=rtitem.CreateNavigator

			Call rtnav.FindLastElement(RTELEM_TYPE_TABLE)

			Set rtt = rtnav.GetElement

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("Number")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("Sub")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("Hybrid")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("Size")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("Type")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("Qty")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			hst$=""

			For x= 1 To vec2.Count 'sub

				

				Set entry2=vec2.GetNthEntry(x)

				Set doc3=entry2.Document

				

				' check if new hybrid-size-type here

				' if yes, write out table with total qty for that combination else totalthat combination

				If (hst$=doc3.DOHHYB(0)+"-"+doc3.DOHSIZ(0)+"-"+doc3.DOHTYP(0)) Or x=1 Then

					qtytotal=qtytotal+doc3.DOHQTY(0)

					hyb$=doc3.DOHHYB(0)

					siz$=doc3.DOHSIZ(0)

					typ$=doc3.DOHTYP(0)

					cus$=Cstr(doc3.CustNum(0))

					cussub$=Cstr(doc3.SubNum(0))

					hst$=doc3.DOHHYB(0)+"-"+doc3.DOHSIZ(0)+"-"+doc3.DOHTYP(0)

				Else

					Call rtt.AddRow(1)

					

					Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

					Call rtitem.BeginInsert(rtnav,False)

					Call rtitem.AppendText(cus$)

					Call rtitem.EndInsert

					Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

					Call rtitem.BeginInsert(rtnav,False)

					Call rtitem.AppendText(cussub$)

					Call rtitem.EndInsert

					Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

					Call rtitem.BeginInsert(rtnav,False)

					Call rtitem.AppendText(hyb$)

					Call rtitem.EndInsert

					Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

					Call rtitem.BeginInsert(rtnav,False)

					Call rtitem.AppendText(siz$)

					Call rtitem.EndInsert

					Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

					Call rtitem.BeginInsert(rtnav,False)

					Call rtitem.AppendText(typ$)

					Call rtitem.EndInsert

					Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

					Call rtitem.BeginInsert(rtnav,False)

					cytotal=cytotal+qtytotal

					Call rtitem.AppendText(Cstr(qtytotal))

					Call rtitem.EndInsert

					qtytotal=0

					

					qtytotal=qtytotal+doc3.DOHQTY(0)

					hyb$=doc3.DOHHYB(0)

					siz$=doc3.DOHSIZ(0)

					typ$=doc3.DOHTYP(0)

					cus$=Cstr(doc3.CustNum(0))

					cussub$=Cstr(doc3.SubNum(0))

					hst$=doc3.DOHHYB(0)+"-"+doc3.DOHSIZ(0)+"-"+doc3.DOHTYP(0)

				End If

			Next

			Call rtt.AddRow(1)

			

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText(cus$)

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText(cussub$)

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText(hyb$)

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText(siz$)

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText(typ$)

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			cytotal=cytotal+qtytotal

			Call rtitem.AppendText(Cstr(qtytotal))

			Call rtitem.EndInsert

			

			Call rtt.AddRow(1)

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			Call rtitem.AppendText("Total")

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

			Call rtitem.BeginInsert(rtnav,False)

			custcytotal=custcytotal+cytotal

			Call rtitem.AppendText(cytotal)

			cytotal=0

			Call rtitem.EndInsert

			Call rtnav.FindNextElement(RTELEM_TYPE_TEXTRUN)

		End If

		

		Call rtitem.AddNewline(1)

		

		

			'get coll of py del and write out table

		key2$=Cstr(doc2.DMCUST(0))+"-"+subnum$			

		Set vec2=view3.GetAllEntriesByKey(key2$,True)

		

	' sort this view by hybrid-size-type and total for each

		

		If vec2.Count=0 Then

			Call rtitem.AppendText("No deliveries for previous year.")

			Call rtitem.AddNewLine(1)	

			linecount=linecount+1

		Else			

			Call rtitem.AppendText("Previous Year Deliveries")

			Call rtitem.AddNewline(1)

’ build py del table

			For column = 1 To 6

				Set rtpStyle = session.CreateRichTextParagraphStyle 

				

				If column = 6 Then

					rtpStyle.RightMargin = RULER_ONE_INCH * .75

					rtpStyle.FirstLineLeftMargin = 0

					rtpStyle.LeftMargin = 0

					rtpStyle.ALIGNMENT=ALIGN_RIGHT

				Else

					rtpStyle.RightMargin = RULER_ONE_INCH * .75

					rtpStyle.FirstLineLeftMargin = 0

					rtpStyle.LeftMargin = 0

					rtpStyle.ALIGNMENT=ALIGN_LEFT

				End If

				

				Set rtps(column) = rtpStyle

			Next

Call rtitem.AppendTable(1,6,“”,RULER_ONE_INCH,rtps)<–this is where it bombs

							Set rtnav=rtitem.CreateNavigator

			Call rtnav.FindLastElement(RTELEM_TYPE_TABLE) 

.

.

.

Any help is greatly appreciated.