IBM Support

How to use LotusScript classes with Visual Basic

Technote (FAQ)


How can you use Visual Basic to create or manipulate IBM Notes documents?


NOTE: All the code below is a sample, provided to illustrate one way to approach this issue. It is to be used as is and at your own risk. In order for this example to perform as intended, the script must be laid out exactly as indicated below. Product Support cannot customize this script for specific environments or applications.
To access LotusScript classes, methods, and properties from Visual Basic, you must first create a NotesSession object. The following code sample illustrates the proper way to do this:

    Dim Session As Object
    Set Session = CreateObject("Notes.Notessession")

NOTE: Notes must be installed on your system to use the Notes classes.

Below is a more complex code sample that uses the CreateDocument method (of the NotesDatabase Class) and the Send method (of the NotesDocument Class). You can use the object browser in Visual Basic to view available methods and properties.

The following example utilizes the database, Test.nsf, which is based on the Discussion Database template.

1. In Visual Basic, create a text box on form1. By default, the field will be "text1".

2. Make the default entry, "Enter Name".

3. Add a button and enter the code below in the Click event.
    Dim Session As Object
    Dim db As Object
    Dim doc As Object
    Dim Doc2 As Object

    Set Session = CreateObject("Notes.Notessession")
    Set db = Session.GetDatabase("", "Test.nsf")
    Set doc = db.createdocument()
    doc.Form = "Main Topic"
    doc.Subject = "Topic created in VB"
    doc.Categories = "Visual Basic"
    Call, True)
    Set Doc2 = db.createdocument()
    doc.Form = "memo"
    doc.Subject = "This doc was created and mailed from VB6"
    If Form1.Text1.Text = "Enter Name" Then
      Call doc.Send(False, "Jane Smith")
      Call doc.Send(False, Form1.Text1.Text)
    End If
When you run the application, a new document is created in the Test discussion database and an e-mail is sent to the name entered in the text box (or, if no name is entered, the message is sent to Jane Smith).

Supporting information:
The Object Browser Online Help in Visual Basic is accessed via the following menu options: View --> Object Browser. You can then highlight the desired item for more information.

To enable the Lotus Notes classes to appear in the Visual Basic browser, you must execute the following within Visual Basic: From the Tools menu, choose References --> select the checkbox for "Lotus Notes Automation Classes".

Document information

More support for: IBM Notes

Software version: 8.0, 8.5, 9.0

Operating system(s): Linux, Windows

Reference #: 1092121

Modified date: 09 June 2003

Translate this page: