I need to compose all the documents in a view called “Comfirmed Order” using the form “PO2”, and then save these new created documents in the same database(The orginal documents are kept unchanged).
Informations:
(1) the documents in the view “Comfirmed Order” : Form = “PO1”
(2)My code is as follows:
Set doc = view.GetFirstDocument 'view: Comfirmed Order
While(Not doc Is Nothing)
Dim uidoc As NotesUIDocument
Set uidoc = ws.ComposeDocument("","","PO2")
Call uidoc.Save
Call uidoc.Close(True)
Set doc = view.GetNextDocument(doc)
Wend
The problem is the uidocs got in the loop are same: it is always the uidoc(Form = “PO2”) based on the first document in the “Comfirmed Order”.
I wonder how to use the ComposeDocument method and is there alternative way to do the job stated above.
Best Regards for all!
Subject: Terrible: about ComposeDocument problem
If I can guess at your goal, you want each new document to inherit from the corresponding original document, but instead they are inheriting from the first document. That is because the selected document does not change when you cycle through the view with GetNextDocument. The more usual solution is to simply copy the backend document and make any changes necessary to clean up fields that are not used. The code would then be more like:
Set doc = view.GetFirstDocument 'view: Comfirmed Order
While(Not doc Is Nothing)
Set doc2 = doc.CopyToDatabase(db) ' Copies to the same db
doc2.Form = "PO2"
' *** clear or set any values to doc2 that match "composing"
...
Call doc2.Save(True, False)
Set doc = view.GetNextDocument(doc)
Wend
Subject: RE: Terrible: about ComposeDocument problem
Thank you for your help. I have considered the way you stated above to compose these documents. But you know, there are so many items in the form “PO2”. I wonder is there a better way to achieve my goal?
Subject: Terrible: about ComposeDocument problem
You are probably having a timing issue with your documents remaining open in the UI even after you tell the UI to close them. There is probably no reason for you to have to use the UI since the “U” is never actually entering any data.
Instead of using NotesWorkspace.ComposeDocument, you shold use NotesDatabase.CreateDocument (which does not use the UI). However, if the reason you need to have the UI open is to inheirt some field values, then you will need to write code to copy those values to the new docuement and possibly do a NotesDocument.ComputeWithForm.