Action Button in Embedded View

I am experiencing a very frustrating issue that I hope someone can shed some light on. I have a form with an single category embedded view.

The view displays all CR documents that relate to the FN doc that contains the embedded view.

On the embedded view, there are three action buttons (one to add a CR, one to edit a CR and one to delete a CR). The Add and Edit buttons

work fine, but the Delete button is giving me grief. When clicking on delete, it should update the FN document in two ways: Remove

references to the CR in two fields and update a few log fields.

If I go directly to the view (not through the embedded view), everything works as expected. When I click it on the embedded view, it

doesn’t remove the CR references from the two FN Doc fields and only updates 2 of the log fields on the FN.

Does this make any sense? Does anyone have any suggestions?

Sub Click(Source As Button)

Dim s As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim col As NotesDocumentCollection 

Dim docFN As NotesDocument 

Dim docCR As NotesDocument

Dim docCRnext As NotesDocument 

Dim uidoc As NotesUIDocument 

Dim itemBU As NotesItem

Dim itemID As NotesItem 

Dim index As Integer 



Set db = s.CurrentDatabase 

Set col = db.UnprocessedDocuments 

Set docCR = col.GetFirstDocument 



Set docFN = db.GetDocumentByUNID(docCR.ParentUNID(0))

Set itemID = docFN.GetFirstItem("CRDocIDs")

Set itemBU = docFN.GetFirstItem("CRBusinessUnit")



Do Until docCR Is Nothing

	Set docCRnext = col.GetNextDocument(docCR)

	index = Arraygetindex(itemID.Values, docCR.UniversalID)

	itemBU.Values = Fulltrim(ReplaceElement(itemBU.Values, index, ""))

	itemID.Values = Fulltrim(ReplaceElement(itemID.Values, index, ""))

	Call UpdateLogCR(docFN, docCR, "Removed")

	Call docCR.Remove(True)

	Set docCR = docCRnext

Loop

Call docFN.Save(True,True)	

Call ws.ViewRefresh 	

End Sub

Function ReplaceElement(v As Variant, position As Integer, newValue As String) As Variant

v(position) = newValue

ReplaceElement = v

End Function

Function UpdateLogCR(docFN As NotesDocument, docCR As NotesDocument, action As String)

'This function updates the log data for a Cross Reference Class Plan change

'The data is updated on the parent File Note document



Dim Session As New NotesSession

Dim itmTemp As NotesItem 



If docFN.GetItemValue("CompanyNameListLogCR")(0) = "" Then

	

	Call docFN.ReplaceItemValue("ChangeDateCR", Cstr(Today))

	Call docFN.ReplaceItemValue("ChangeActionCR", action)

	Call docFN.ReplaceItemValue("ChangeNameCR", session.CommonUserName)

	Call docFN.ReplaceItemValue("CompanyNameListLogCR", docCR.CoName(0))

	Call docFN.ReplaceItemValue("BlockNameListLogCR", docCR.Block(0))

	Call docFN.ReplaceItemValue("PrimaryNameListLogCR", docCR.Primary(0))

	Call docFN.ReplaceItemValue("SecondaryNameListLogCR", docCR.SecCode(0))

	

	If docCR.TerCode(0) = "" Then

		Call docFN.ReplaceItemValue("TertiaryNameListLogCR", "<blank>")

	Else

		Call docFN.ReplaceItemValue("TertiaryNameListLogCR", docCR.TerCode(0))

	End If

	

Else

	

	Set itmTemp = docFN.GetFirstItem( "ChangeDateCR" )

	Call itmTemp.AppendToTextList(Cstr(Today))

	

	Set itmTemp = docFN.GetFirstItem( "ChangeActionCR" )

	Call itmTemp.AppendToTextList(action)

	

	Set itmTemp = docFN.GetFirstItem( "ChangeNameCR" )

	Call itmTemp.AppendToTextList(session.CommonUserName)

	

	Set itmTemp = docFN.GetFirstItem( "CompanyNameListLogCR" )

	Call itmTemp.AppendToTextList( docCR.CoName(0))

	

	Set itmTemp = docFN.GetFirstItem( "BlockNameListLogCR" )

	Call itmTemp.AppendToTextList( docCR.Block(0))

	

	Set itmTemp = docFN.GetFirstItem( "PrimaryNameListLogCR" )

	Call itmTemp.AppendToTextList( docCR.Primary(0))

	

	Set itmTemp = docFN.GetFirstItem( "SecondaryNameListLogCR" )

	Call itmTemp.AppendToTextList( docCR.SecCode(0))

	

	If docCR.TerCode(0) = "" Then

		Set itmTemp = docFN.GetFirstItem( "TertiaryNameListLogCR" )

		Call itmTemp.AppendToTextList( "<blank>")

	Else

		Set itmTemp = docFN.GetFirstItem( "TertiaryNameListLogCR" )

		Call itmTemp.AppendToTextList( docCR.TerCode(0))

	End If

End If

End Function