I am working on a database and would like to take information from my form fields to create a new document in a different database and auto-populate some fields with the ones from my current database -- basically take information from a database and use it in another. How do I open the other database and the form and then populate the fields? Thanks.
I wouldn't bother to open the other database onscreen unless you really think the user will want it open, because it just makes an extra step for the user to close that window.
Field inheritance doesn't work across databases, so your code will need to assign the fields "manually."
Sub Click(Source As Button) Dim ws As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim doc As NotesDocument Dim otherDB As NotesDatabase Dim otherDoc As NotesDocument Set uidoc = ws.CurrentDocument If uidoc.EditMode Then On Error Resume Next ' ignore all errors (in particular, alidation failures) uidoc.Refresh True ' make sure RTFs and computed fields up to date in back end. On Error Goto 0 ' resume normal error handling. End If Set doc = uidoc.Document Set otherDB = New NotesDatabase (otherdbserver, otherdbpath) If Not otherDB.IsOpen Then Messagebox "Cannot find other database." Exit Sub End If Set otherDoc = otherDB.CreateDocument otherDoc.Form = "OtherForm" ' Copy each field we need from the old form, to the new form. otherDoc.Field1 = doc.FieldA otherDoc.Field2 = doc.FieldB ' ... ' here's how to copy a rich text field. Dim rtf As Variant Set rtf = doc.GetFirstItem("Body") Call rtf.CopyItemToDocument(otherDoc, "fieldname") ' note: in R5, may miss fonts, file attachments and objects. ' ... Call otherDoc.ComputeWithForm (False, False) ' only needed if we copied rich text fields. Call ws.EditDocument(True, otherDoc) End SubWarning: The macro function @IsNewDoc returns False when a document is opened using EditDocument, even if the document has not been saved.
Dig Deeper on LotusScript
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.