18.01.2013 Views

LotusScript for Visual Basic Programmers - IBM Redbooks

LotusScript for Visual Basic Programmers - IBM Redbooks

LotusScript for Visual Basic Programmers - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Dim doc As Object<br />

We create a reference to the Notes object that is created externally.<br />

Set session = CreateObject("Notes.NotesSession")<br />

We use the Notes object hierarchy to create the object db to access the<br />

Notes database TEST on the local server. For the GetDatabase method,<br />

the first parameter is the server name, the second parameter is the<br />

database file name. If the server is a local server, specify an empty<br />

string, as in our example.<br />

Set db = session.GetDatabase("", "test.nsf")<br />

We use the Notes hierarchy to create the doc object to access a Notes<br />

document.<br />

Set doc = db.CreateDocument()<br />

We use the Main Topic <strong>for</strong>m to create the document.<br />

doc.Form = "Main Topic"<br />

Fill the Subject and Body text fields with the contents of the text boxes<br />

in the <strong>Visual</strong> <strong>Basic</strong> application.<br />

doc.Subject = Form1.Text3.Text<br />

doc.Body = Form1.Text2.Text<br />

We use the Save method to save the document. We want the document<br />

to be saved even if someone else edits and saves the document while<br />

the application is running. So we set True in the first argument.<br />

Otherwise when someone else edits the document while the application<br />

is running, the second argument determines what happens.<br />

Call doc.Save(True, False)<br />

3. Put the following code on the Exit command button:<br />

Private Sub Command2_Click()<br />

Set db = Nothing<br />

Set session = Nothing<br />

Unload Form1<br />

End Sub<br />

Following is an explanation of the code.<br />

We release object db and object session be<strong>for</strong>e we exit the application.<br />

Set db = Nothing<br />

Set session = Nothing<br />

88 <strong>LotusScript</strong> <strong>for</strong> <strong>Visual</strong> <strong>Basic</strong> <strong>Programmers</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!