Q
Problem solve Get help with specific problems with your technologies, process and projects.

How can I open a database and a form and populate the fields with info from another database?

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 Sub
Warning: 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.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close