Technote (FAQ)
Question
How can you use Visual Basic to create or manipulate Lotus Notes® documents?
Answer
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.
Example:
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 doc.save(True, 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)
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".
Related information
Notes Does Not Support Early Binding in OLE via LotusSc
Rate this page:
Copyright and trademark information
IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.