Creating a response document and attempting to use PostOpen

I am in a document that has a button to create another document. On the new document to be created, there is a field containing the id of the parent document, computed when composed. As part of initially creating this new document, I need to get a piece of data from a third document, whose document id exists in the parent document. On the postopen script for the new document, I check for isnewnote (figured out that isnewdoc wouldn’t work), and if it is, then I get the other document’s id from the parent document, get a field value from that document, and put it in a field on this new document.

Anyway, that’s what I want, but it doesn’t work. Here is my code on the button of the parent document that will create the new doc if it doesn’t exist:

Dim ws As New NotesUIWorkspace

Dim uidb As NotesUIDatabase

Dim uidoc As NotesUIDocument

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim unid As String

Dim workingdoc As NotesDocument

Dim cDoc As NotesDocument

Set uidb = ws.CurrentDatabase

Set uidoc = ws.CurrentDocument

Set db = uidb.Database

Set workingdoc = uidoc.Document

Call workingdoc.Save (True, True)

unid = workingdoc.RecDID(0)	

If unid = "" Then 

	Call ws.ComposeDocument( "", "", "RecD 1.9",,1)

Else

	Set cDoc = db.GetDocumentByUNID(unid)

	Set uidoc = ws.EditDocument(False, cDoc)

End If

Here is my code on the postopen event of the new RecD 1.9 document :

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Set db = session.CurrentDatabase	

Dim unid As String

Dim workingdoc As NotesDocument

Dim cunid As String

Dim cdoc As NotesDocument

Dim cdadoc As NotesDocument

Dim item As NotesItem

Dim citem As NotesItem

Set cdoc = source.Document

If cdoc.IsNewNote Then

	'only when it is a new doc, we want to get the ViolationPolicy from the CDA

	unid = cdoc.ParentID(0)	

	Set workingdoc = db.GetDocumentByUNID(unid)

	cunid = workingdoc.CDAID(0)	

	Set cdadoc = db.GetDocumentByUNID(cunid)

	Set item = cdadoc.GetFirstItem( "ViolationPolicy" )

	Call item.CopyItemToDocument( cdoc, "ViolationPolicy" )

	Exit Sub

End If

I’ve tried putting a messagebox in the If statement that checks for a newnote, and outside the if statement, and as the first line in the postopen, it never displays the message, it’s like it never tries to run the postopen. I can’t debug because as soon as my script gets to the point that it does the compose document in the button, the document gets created but doesn’t become the uidocument or something, I’m still on the first document but the created document is now another tab in my client. When I just create the document from the Create menu with the parent document selected it works correctly, but that’s not how it needs to be used, the user needs to be in the parent document.

Any help would be greatly appreciated!