Newbie: Pull existing data into new doc, w/o using "formulas inherit values.." option

I am trying to pull information from certain fields on an existing doc into a new doc based on a different form using an action button in a view.

There are different types of forms in the view, so I need to setup a check of the form name first, and then populate the fields if there is a match. I also need those fields to be editable as some of the information will have changed.

I am having problems getting the button to run from a view (various “object variable not set” or “not a member” error messages).

Can someone provide me with some guidance on how to set the selected document in the view as the one I want to pull the data from, and then how to transfer those values to the new document. I have tried modifying some of the examples in Help using “fieldgettext” and “fieldsettext” with no success.

Thank you for any assistance.

Subject: Newbie: Pull existing data into new doc, w/o using “formulas inherit values…” option

You need to use the UnprocessedDocuments property to get a handle on the documents that are selected. Something like this:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim newDoc as Notesdocument

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

Set doc = collection.GetFirstDocument()

While Not(doc Is Nothing)

'Check for the form name

If doc.form(0) = "123" Then

  'Create new document and set fields

  Set newDoc = New Notesdocument(db)

  newDoc.field1 = doc.field1(0)

  'save newDoc

  call newDoc.save(true, true)

Endif

Set doc = collection.GetNextDocument(doc)

Wend

Subject: RE: Newbie: Pull existing data into new doc, w/o using “formulas inherit values…” option

Rellim,

This works fine, but how do I get it so the new document created is visible on the screen and opened in edit mode?

Thanks again.

Subject: RE: Newbie: Pull existing data into new doc, w/o using “formulas inherit values…” option

Dim workspace as New Notesuiworkspace

'Put this line after the newDoc.save or omit the save if you don’t want to save the new document until the user makes changes.

Call workspace.EditDocument(True, newDoc)

Subject: RE: Newbie: Pull existing data into new doc, w/o using “formulas inherit values…” option

Thank you for your response. That is much less code than what I had :slight_smile: I will try it out and keep my fingers crossed.