Examples: NotesDatabase class

  1. This script creates a NotesDatabase object called db and uses New to assign a database to it. The database is located at the top level of the Domino® data directory on server Barcelona. If the database exists, New automatically opens the database, so you can access the database properties and methods immediately.
    Dim db As NotesDatabase
    Set db = New NotesDatabase( "Barcelona", "plan.nsf" )
    Messagebox( db.Title )
  2. This script achieves the same result as the preceding example, but declares a NotesDatabase object db and calls New in one line.
    Dim db As New NotesDatabase( "Barcelona", "plan.nsf" )
    Messagebox( db.Title )
  3. This script uses IsOpen to test if the database QUACK.NSF exists on the current computer. If not, it uses the Create method to create a new database on disk.
    Dim db As New NotesDatabase( "", "quack.nsf" )
    If db.IsOpen Then
      Messagebox( "The database quack.nsf already exists." )
    Else
      Messagebox( "Creating the database quack.nsf...")
      Call db.Create( "", "", True )
      db.Title = "Ducks of North America"
    End If
  4. This script calls New while declaring the db object. It assigns db to a database located in a directory called SOUNDS, inside the directory SENSES. (The SENSES directory, in turn, is located inside the Domino® data directory.)

    If this script runs on a workstation, it opens the CLUNK.NSF database on the local computer.

    If this script runs on the server Khartoum, it opens the CLUNK.NSF database on the server Khartoum.

    Dim db As New NotesDatabase _
    ( "", "senses\sounds\clunk.nsf" )

    On a Macintosh, if CLUNK.NSF is located in the Sounds folder, inside the Senses folder, the script looks like this:

    Dim db As New NotesDatabase _
    ( "", "senses:sounds:clunk.nsf" )
  5. This script gives Brian Flokka Editor access to the current database. The current database is the one in which the script is running. Using the CurrentDatabase property in NotesSession avoids the need to use file names in scripts and makes scripts easily portable from one database to another.
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Set db = session.CurrentDatabase
    Call db.GrantAccess( "Brian Flokka", ACLLEVEL_EDITOR )
  6. This script uses the Open method to check if a database exists on the server Asuncion. If the database exists, the script adds the Supervisors group to the ACL; if it doesn't exist, the script does nothing.
    Dim db As New NotesDatabase( "", "" )
    If db.Open( "Asuncion", "salesdocs.nsf" ) Then
      Call db.GrantAccess( "Supervisors", ACLLEVEL_EDITOR )
    End If
  7. This script shows how you can use New in combination with the OpenIfModified method to open a database only if it's been modified after a certain date. The script checks if SALESDOCS.NSF on the current server has been modified since yesterday--if so, it opens the database and compacts it.
    Dim db As New NotesDatabase( "", "" )
    Dim dateTime As New NotesDateTime( "Today" )
    Call dateTime.AdjustDay( -1 )
    If db.OpenIfModified( "", "salesdocs.nsf", dateTime ) Then
      Call db.Compact
    End If
  8. This script uses New in combination with the CreateFromTemplate method to create a new discussion database on the server Juno.
    Dim template As New NotesDatabase _
    ( "Anchorage", "discuss.ntf" )
    Dim brandNewDb As NotesDatabase
    Set brandNewDb = template.CreateFromTemplate _
    ( "Juno", "suggest.nsf", True )
    brandNewDb.Title = "Suggestions for Giving Campaign 1996"