Option Public Option Declare Sub Initialize Dim s as New NotesSession Dim db as NotesDatabase ' current database Dim agtitle as String ' agent full title (including alias) Dim agnoteid as String ' agent note id Dim agDoc as NotesDocument ' agent as document Dim db2 as NotesDatabase ' second database to get Dim db2Ag as NotesAgent ' agent in second database, used to verify doesn't already exist ... agtitle = "MyAgentTitle" ' get the note id for agent agnoteid = GetAgentNoteID(db, agtitle) If (agnoteid = "") Then Exit Sub End If ' get the agent as a document Set agDoc = db.GetDocumentByID(agnoteid) If (agDoc is Nothing) Then Exit Sub End If ... ' copy the agent to 2nd db Set db2Ag = db2.GetAgent(agtitle) If Not db2Ag Is Nothing) Then ' agent already already exists, done ProcessPerson = 1 Exit Function Else ' doesn't exist copy it Call agDoc.CopyToDatabase(db2) ProcessPerson = 1 End If ... End Sub Function GetAgentNoteID(db As NotesDatabase, agtitle As String) As String ' get's all agents in database and returns agent ID ' useful to get agent as a document Dim s As New NotesSession Dim nnC As NotesNoteCollection ' collection of views Dim nid As String ' note id of each note in nnc (view) Dim doc As NotesDocument ' getting agent design notes by id Dim dItem As NotesItem ' title of view note of doc Dim dtitle As String ' alias/title of agent On Error Goto FErrorHandler GetAgentNoteID = "" ' do tests If (db Is Nothing) Then Exit Function End If If (agtitle = "") Then Exit Function End If ' create empty collection object Set nnC = db.CreateNoteCollection(False) ' start emply nnC.SelectAgents = True Call nnC.BuildCollection ' contains all agents in db nid = nnC.GetFirstNoteId() While Not (nid = "") ' get the "document" for the agent and then its title Print nid Set doc = db.GetDocumentByID(nid) If (doc Is Nothing) Then Print "No doc for id: " & nid "." Else Set dItem = doc.GetFirstItem("$TITLE") If (dItem Is Nothing) Then Print "Skipped: " & nid & ". No title." Else ' get the view title/alias so we can get the view dtitle = dItem.Text If (Strcompare(dtitle, agtitle, 5) =0) Then ' exact match, have agent, return id and stop looping GetAgentNoteID = nid Set dItem = Nothing Set doc = Nothing Goto FExit End If End If End If ' get next id dtitle = "" Set dItem = Nothing Set doc = Nothing nid = nnC.GetNextNoteId(nid) Wend ' done return current value FExit: Exit Function FErrorHandler: Print "(GetAgentNoteID) Unexpected Error: " & Cstr(Err) & " " & Error$ & ", on line: " & Cstr(Erl) & "." GetAgentNoteID = "" Resume FExit End Function