Notes & VB

I'm looking for a VB sample that does the following:

1) Connects to a Notes database
2) Finds a certain document based on a simple criteria
3) Modifies some fields on the document
4) Saves the document
5) Closes the connection

LVL 13
MirkwoodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HemanthaKumarCommented:
Hi
Here is a note which gives you some info on how to access notes environment via VB script.




Using Notes Classes in Visual Basic
===================================

Visual Basic programmers can access Notes objects through the Notes.NotesUIWorkspace and Notes.Session OLE automation objects. Notes must be installed on the same machine as the Visual Basic program. NotesUIWorkspace and NotesSession head hierarchies that give you access to all the Notes classes.

In Visual Basic, you cannot create new Notes objects as in LotusScript. You must apply CreateObject to Notes.NotesUIWorkspace or Notes.Session and work down through the hierarchies using the available methods. For example, if you want to open a Notes database in the back-end, use CreateObject to create a Notes.Session OLE automation object, then use the GetDatabase method of NotesSession to set a reference variable of type Object.
In Visual Basic, declare the reference variables for all Notes objects as type Object. When you finish using a Notes object, set the reference variable to Nothing to free the memory it uses.  Use dot notation, just as in LotusScript, to access an object's properties and methods.  Constants must be specified by actual numeric value rather than name. In LotusScript, you can get the value by displaying it. For example: Messagebox ACLLEVEL_AUTHOR,, "ACLLEVEL_AUTHOR"

Examples: Using Notes Classes in Visual Basic
Example #1:This example represents two command buttons on a Visual Basic form.
The first button writes a new document in an existing Notes database by creating a NotesSession object through OLE and creating NotesDatabase and NotesDocument objects through Notes methods. The second button frees the memory used by the Notes object before unloading the Visual Basic form.

Private Sub Command1_Click()

    Dim session As Object
    Dim db As Object
    Dim doc As Object

    Set session = CreateObject("Notes.NotesSession")
    Set db = session.GetDatabase("", "test4.nsf")
    Set doc = db.CreateDocument()

    doc.Form = "Main Topic"
    doc.Subject = Form1.Text3.Text
    doc.Body = Form1.Text2.Text
    Call doc.Save(True, False)

End Sub

Private Sub Command2_Click()

    Set doc = Nothing
    Set db = Nothing
    Set session = Nothing
    Unload Form1

End Sub

Example #2: This example represents a command button on a Visual Basic form.
The button launches Notes if it is not already running, then opens test4.nsf in the local data directory.

Private Sub Command3_Click()

    Dim ws As Object

    Set ws = CreateObject("Notes.NotesUIWorkspace")
    Call ws.OpenDatabase("", "test4.nsf")


0
MirkwoodAuthor Commented:
Doesn't answer the find question...
0
HemanthaKumarCommented:
Hi

Hope you have understood the logic what I am trying to explain. Use db.FTSearch method to search the documents

syntax for that is:

Set notesDocumentCollection = notesDatabase.FTSearch( query$, maxDocs% [,sortoptions [, otheroptions]] )

You can find lots of example in Notes Help for searching documents.

PS:I hope that the answer gives you the most of it u asked for. Don't take it other way but sometimes few  things should be explored on ur own.

Regards,
~Hemanth
0
stampCommented:
Try this (it worked in WindowScriptingHost):
=============================
Dim s
Dim db  
Dim doc
Dim dc

Set s  = CreateObject("Notes.NotesSession")
Set db = s.GetDatabase("ServerName/Organization", "path/db.nsf")
Set dc = db.FTSearch("field ChangeRequestNr = 123", 1)

Set doc = dc.GetFirstDocument()
doc.Form = "ChangeRequest"
Call doc.Save(True, False)

dc  = Null
doc = Null
db  = Null
s   = Null
===========================

That's all.

Regards,
stamp

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stampCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.