Doc Links and Rich Text Field

There is an existing subform that has the code below to load doc links and titles from one database view to another database form. My main focus is on the section where ‘pdf’ is involved, however I’m not sure what is going on with this. The doclinks are being pulled with the titles, however after every report there is a blank doclink with no title that links back to the 1st doclink when clicked. Any ideas why this extra doclink is showing?

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)

'Loads the doc links to the stewardship reports in stewrpt.nsf

'these doclinks MUST NOT BE SAVED, but loaded in each time

Dim session As New NotesSession

Dim stewRptdb As NotesDatabase

Dim budgArray() As String

Dim budgView As NotesView

Dim stewRpts As NotesDocumentCollection

Dim studRpts As NotesDocumentCollection

Dim studRpt As NotesDocument

Dim donRpt As NotesDocument

Dim pdfRpt As NotesDocument

Dim pdfdonRpt As NotesDocument

Dim rpt As notesDocument

Dim stewRpt As notesDocument

Dim stewRptFld As notesRichTextItem

Dim itemCt As Integer

Dim studCt As Integer

Dim donCt As Integer

Dim pdfCt As Double

Dim pdfdonCt As Double

Dim lnk As String

Dim studLnk As String

Dim donLnk As String

Dim pdfLnk As String

Dim pdfdonLnk As String

Dim fYear As Integer

Dim i As Integer



If Not (Source.isNewDoc) Then

	

	If Not( Trim(Source.document.Budget(0)) = "") Then

	'use budget number for lookup--exit if it is null-otherwise ALL stewardship rpts will load on the doc

		If Not Source.Document.hasItem("StewRptLnk") Then

			Set stewRptFld = New NotesRichTextItem(Source.Document , "StewRptLnk" )

		End If

		Redim budgArray(0)

		budgArray(0) = Trim(Source.document.Budget(0))

		If Source.document.hasItem("budget_stack") Then

			If Source.document.budget_stack(0) <> "" Then

				i = Ubound(budgArray)

				Forall item In Source.document.budget_stack

					Redim Preserve budgArray(i)

					budgArray(i) = Trim(item)

					i = i + 1

				End Forall

			End If

		End If

		'Set stewRptdb = session.GetDatabase("DDAS2/Notes", "stewrpt.nsf")

		Set stewRptdb = session.GetDatabase("DDAS2/Notes", "stewrpt06test.nsf")

		If Not stewRptdb Is Nothing Then

			Set budgView = stewRptdb.getview("BUDG")

			If Not budgView Is Nothing Then

				For i = 0 To Ubound(budgArray)	

					

					Set stewRpts = budgView.getAllDocumentsbyKey(budgArray(i))

					If Not stewRpts Is Nothing Then

						Set stewRpt = stewRpts.getFirstDocument

						If Not stewRpt Is Nothing Then

							fYear = stewRpt.fy(0)

						End If

						Set rpt = stewRpt

						While Not rpt Is Nothing

				'add the stew reports as links in the StewRpt field

				'first get the rpt name

							

							

							If rpt.form(0) = "D_RPT" Then

								If donCt = 0 Then

									Set donRpt = rpt

									donLnk = Trim(Str(rpt.fy(0))) + " Donor Report for "

								End If

								donCt = donCt + 1

								If donCt > 1 Then

									donLnk = donLnk + ", "

								End If

								If rpt.DonorName(0) = "No Report Sent" Then

									donLnk = donLnk + " -- not sent"

								Else										

									donLnk = donLnk + rpt.DonorName(0)

								End If

'pyb

							Elseif rpt.form(0) = "pdf" And rpt.RptType(0) = "Donor Report" Then

								If pdfdonCt = 0 Then

									Set pdfdonRpt = rpt

									pdfdonLnk = Trim(Str(rpt.fy(0))) + " Donor Report for "

								End If

								pdfdonCt = pdfdonCt + 1

								If pdfdonCt > 1 Then

									pdfdonLnk = pdfdonLnk + ", "

								End If

								If rpt.DonorName(0) = "No Report Sent" Then

									pdfdonLnk = pdfdonLnk + " -- not sent"

								Else

									pdfdonLnk = pdfdonLnk + rpt.budget(0)

								End If					

								

							Elseif rpt.form(0) = "pdf" And rpt.RptType(0) = "Student Report" Then

								If pdfCt = 0 Then

									Set pdfRpt = rpt

									pdfLnk = Trim(Str(rpt.fy(0))) + " Student Report for "

								End If

								pdfCt = pdfCt + 1

								If pdfCt > 1 Then

									pdfLnk = pdfLnk + ", "

								End If

								'If rpt.DonorName(0) = "No Report Sent" Then

								'	pdfLnk = pdfLnk + " -- not sent"

								'Else

								'pdfLnk = pdfLnk + rpt.budget(0)

								pdfLnk = pdfLnk + rpt.dspbudget(0)

							'End If

'end pyb

							Elseif rpt.form(0) = "S_RPT" Then

								If studCt = 0 Then

									Set studRpt = rpt

									studLnk = Trim(Str(rpt.fy(0))) + " Student Report  for "

								End If

								studCt = studCt + 1

								If studCt > 1 Then

									studLnk = studLnk + ", "

								End If

								If rpt.DonorName(0) = "No Report Sent" Then

									studLnk = studLnk + " -- not sent"

								Else

									studLnk = studLnk  + rpt.DonorName(0)

								End If

							End If

							

					'since student reports are children of donor reports, need to get them thru each donor report

							If rpt.form(0) = "D_RPT" Then

								Set studRpts = stewRpt.Responses

								If Not studRpts Is Nothing Then

									If studRpts.count > 0 Then

										Set rpt = studRpts.getfirstdocument

										If Not(rpt.hasItem("fy")) Then 'if student report has no fy it is just a stub, move on

											Set stewRpt = stewRpts.getNextDocument(stewRpt)

											Set rpt = stewRpt

										End If

									Else 'if we can't get a student report, get the next donor report

										Set stewRpt = stewRpts.getNextDocument(stewRpt)

										Set rpt = stewRpt

									End If

								Else

									Set stewRpt = stewRpts.getNextDocument(stewRpt)

									Set rpt = stewRpt

								End If

							Elseif rpt.form(0) = "S_RPT" Then

								Set stewRpt = stewRpts.getNextDocument(stewRpt)

								Set rpt = stewRpt

'pyb

							Elseif rpt.form(0) = "pdf" Then

								Set stewRpt = stewRpts.getNextDocument(stewRpt)

								Set rpt = stewRpt

'end pyb

							End If

							

							If Not rpt Is Nothing Then

								

								If rpt.fy(0) <> fYear Then

									If stewRptFld Is Nothing Then

										Set stewRptFld = Source.document.GetFirstItem( "StewRptLnk" )

									End If

									

									If stewRptFld.Type = RICHTEXT Then

										

										Call stewRptFld.AppendDocLink( donRpt, donLnk)

										Call stewRptFld.AppendText(donLnk)

										

										If Not studRpt Is Nothing Then

											Call stewRptFld.AddNewLine( 1 )

											Call stewRptFld.AppendDocLink(studRpt, studLnk)

											Call stewRptFld.AppendText(studLnk)

										End If

										

										If Not pdfRpt Is Nothing Then

											Call stewRptFld.AddNewLine( 1 )

											Call stewRptFld.AppendDocLink(pdfdonRpt, pdfdonLnk)

											Call stewRptFld.AppendText(pdfdonLnk)

										End If

										

										If Not pdfRpt Is Nothing Then

											Call stewRptFld.AddNewLine( 1 )

											Call stewRptFld.AppendDocLink(pdfRpt, pdfLnk)

											Call stewRptFld.AppendText(pdfLnk)

										End If

										

										donCt = 0

										studCt = 0

'pyb

										pdfCt = 0

										pdfdonCt = 0

'end pyb

										donLnk = ""

										studLnk = ""

										pdfLnk = ""

										pdfdonLnk = ""

										fYear = rpt.fy(0)

										Call stewRptFld.AddNewLine( 1 )

										

									End If

								End If

							Else

								If stewRptFld Is Nothing Then

									Set stewRptFld = Source.document.GetFirstItem( "StewRptLnk" )

								End If

								

								If stewRptFld.Type = RICHTEXT Then

									

									Call stewRptFld.AppendDocLink( donRpt, donLnk)

									Call stewRptFld.AppendText(donLnk)

									

									If Not studRpt Is Nothing Then

										Call stewRptFld.AddNewLine( 1 )

										Call stewRptFld.AppendDocLink(studRpt, studLnk)

										Call stewRptFld.AppendText(studLnk)

									End If

									

									If Not pdfRpt Is Nothing Then

										Call stewRptFld.AddNewLine( 1 )

										Call stewRptFld.AppendDocLink(pdfdonRpt, pdfdonLnk)

										Call stewRptFld.AppendText(pdfdonLnk)

									End If										

									

									If Not pdfRpt Is Nothing Then

										Call stewRptFld.AddNewLine( 1 )

										Call stewRptFld.AppendDocLink(pdfRpt, pdfLnk)

										Call stewRptFld.AppendText(pdfLnk)

									End If

									

								End If

								

							End If	

							

						Wend

						

					End If

				Next

			End If

		End If

	End If

End If

End Sub

Subject: Doc Links and Rich Text Field-EXAMPLE OF WHAT I’M GETTING

Perhaps an example of what I ‘AM’ getting might help. I’m getting all of the doc links with the report titles that I’ve asked for, however between them I am getting a doclink with no title when clicked links to the 1st doclink form.

[doclink] 2007 Student Report for 0901004 HY

[doclink] 2001 Donor Report for John J. Messmer III

[doclink]

[doclink] 2002 Donor Report for John J. Messmer III

[doclink]

[doclink] 2003 Donor Report for John J. Messmer III

[doclink]

[doclink] 2004 Donor Report for – not sent

[doclink]

[doclink] 2005 Donor Report for – not sent

[doclink] 2005 Student Report for – not sent

Subject: RE: Doc Links and Rich Text Field-EXAMPLE OF WHAT I’M GETTING

I’m not sure but I think you have a logic error. It appears you have 3 types of documents you are creating links to: studRpt, pdfdonRpt and pdfRpt. Accordingly, you have 3 If conditions to check for the existence of the document before you add the doclink.

But if you notice the If for pdfdonRpt, it is actually checking for the existence of pdfRpt. So out of the three Ifs, you are checking studRpt once and pdfRpt twice, never actually checking if pdfdonRpt actually exists before creating the doclink to it. And I think that’s why you have those blank doclink lines.

Correct that If condition and see if that solves your problem. Keep in mind, you actually have two sets of the 3 Ifs, each contained in a higher level IF-Else condition.

Hope that helps.

Subject: RE: Doc Links and Rich Text Field-EXAMPLE OF WHAT I’M GETTING

Thank you - I did correct the If statement for the pdfdonRpt and commented out the last If statement looking for the document. I am still getting the blank doclink that links back to the 1st doclink. I should note that this isn’t my code and orginal programmer left - I was trying to add to her code, but may have to just start from scratch if I can’t get this to work. Thank you for taking the time to review and give input - muchly appreciated!