I recently created this script code to open a 2nd database and view in order to create a new document in it. While debugging I had to comment out lines to CLOSE the view and database. How do you CLOSE them, or do they need to be closed, or do they close automatically?
Below is my code, for your reference.
Sub Click(Source As Button)
'…define environment and UIDoc
Dim Session As NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set Session = New NotesSession
Set db = Session.Currentdatabase
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
'…create variable to store last used number
Dim lastTicketnumber As Long
'…open system db on same server
Dim sysdb As NotesDatabase
Set sysdb = session.getdatabase(db.server,"TestDataB.nsf")
'…open system view to lookup the last document and get the last saved ticket number (key field)
Set sysview = sysdb.getview("hiddenlookup")
Set sysnav = sysview.CreateViewNav
Set sysentry = sysnav.GetLast
Set sysdoc = sysentry.Document
'…place Ticketnumber into variable to use later
lastTicketnumber = sysdoc.ticketnumberB(0)
'…done with system view and document, can close these now, (need sysdb still)
'…THE FOLLOWING 2 “Call” LINES I HAD TO COMMENT OUT TO TEST.
'…THE CODE EXECUTES FINE, BUT DON’T I STILL HAVE A HANDLE ON THESE?
'…WHAT HAPPENS IF THEY ARE NOT CLOSED, OR DO THEY CLOSE AUTOMATICALLY?
’ Call sysdoc.Close(True)
’ Call sysview.Close(True)
'…create a new document in HelpDesk database
Dim newsysdoc As NotesDocument
Set newsysdoc = New NotesDocument(sysdb)
newsysdoc.Form = "mainB"
'…populate fields from UIDoc onto new system doc
newsysdoc.nameB=doc.name(0)
newsysdoc.problemB=doc.problem(0)
newsysdoc.ticketnumberB=lastTicketnumber + 1
doc.hdticket=newsysdoc.ticketnumberB
'…New reference document is created with several fields and new id, save it now
Call newsysdoc.Save (True, True)
'…Close sysdb and save UIDoc
'…ONCE AGAIN, DON’T I NEED TO CLOSE THE SYSDB? WHAT IF I DON’T?
’ Call sysdb.Close(True)
Call doc.Save (True, True)
Call doc.Save(True, True)
End Sub