LOTUSSCRIPT/COM/OLE CLASSES
Examples: Opening a database
1. This example opens a database on the local machine and prints some of the properties of the database object. The user supplies the database name, which does not need the NSF extension.
Sub Initialize
Dim db As New NotesDatabase ("", Inputbox ("File name"))
If db.IsOpen Then
Messagebox "Title: " & db.Title & Chr(10) _
& "File name: " & db.FileName
Else
Messagebox "Could not open database " & db.FileName
End If
End Sub
2. This example opens the current database.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Messagebox "Title: " & db.Title & Chr(10) _
& "File name: " & db.FileName
If db.IsOpen Then msg = "open" Else msg = "not open"
Messagebox "Database is " & msg
End Sub
3. This example shows that the database represented by the object db is closed until opened with the Open method.
Sub Initialize
Dim db As New NotesDatabase("", "")
If db.IsOpen Then Messagebox "Is open" Else Messagebox "Not open"
Call db.Open("", Inputbox("File name?"))
If db.IsOpen Then
Messagebox "Title: " & db.Title & Chr(10) & "Is open" , , _
"File name: " & db.FileName
Else
Messagebox "Not open", , "File name: " & db.FileName
End If
End Sub
4. This example traverses the local databases and opens the database for which the title is specified by the user. The call to the Open method specifies null parameters because the database object already exists, having been returned by the GetFirstDatabase or GetNextDatabase method of NotesDbDirectory.
Sub Initialize
Dim dbdir As New NotesDbDirectory("")
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Set db = dbdir.GetFirstDatabase(DATABASE)
dbTitle = Inputbox("Title of database?")
While Not(db Is Nothing)
If db.Title = dbTitle Then
Call db.Open("", "")
Set dc = db.AllDocuments
Set doc = dc.GetFirstDocument()
While Not(doc Is Nothing)
Messagebox "Subject: " & _
doc.Subject(0)
Set doc = dc.GetNextDocument(doc)
Wend
Exit Sub
End If
Set db = dbdir.GetNextDatabase
Wend
End Sub
5. This example opens the user's mail database.
Sub Initialize
Dim db As New NotesDatabase("", "")
Call db.OpenMail
If db.IsOpen Then
Messagebox "Title: " & db.Title
End If
End Sub
6. This example opens the database on the server Market for which the replica ID is the same as the local database named SALES2.
Sub Initialize
Dim dbLocal As New NotesDatabase("", "SALES2")
Dim dbRemote As New NotesDatabase("", "")
If dbRemote.OpenByReplicaID("Market", _
dbLocal.ReplicaID) Then
Messagebox "Remote database opened OK"
Else
Messagebox "Remote database did not open"
End If
End Sub
See Also
Opening a database
Glossary
Feedback on
Help
or
Product Usability
?
Help on Help
All Help Contents
Glossary