Opening And Viewing A Notes Database From Visual Basic

Have you ever wanted to open and view a Notes Database directly from a Visual
Basic Application? The problem many people run into is they are unable to
force the Notes Application into the Foreground for the user to view. With this
tip, the Notes Application will always open in the foreground with the database
of your choice opened for viewing.
'First you will need to define a Windows API in the declarations section your
VB Project

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As
Long) As Long

'Now from the click event of a Button on a Visual Basic Form, add the following
code.

dim session as Object
dim uiWs as Object
dim dbName as string
dim serverName as string
dim iRet as integer

dbName = "cipher\cipher.nsf" 'The value of this should match the name of the
database you want to open
serverName = "rtpswgs6" 'The server where your database resides

'First Create an Instance of the Session Object. If the Notes Interface is
already running this simply passes focus to it. If the interface is not
running it will start Lotus Notes

set session = CreateObject("Notes.NotesSession")

'Second Make a Call to the Windows API that we defined in the declarations
section. This is the key to the tip. By making a call to this function you
are ensuring that Lotus Notes Moves to the Foreground so the user is guaranteed
to see it.

iRet = ShellExecute(Me.hWnd, "Open", "notes.exe", vbNullString, dummyString,
SW_SHOWNORMAL)


'Now we create an instace of the NotesUIWorkSpace object so that we can open
our database for the user to view and look at

set uiWs = CreateObject("Notes.NotesUIWorkSpace")

'Make a call to the OpenDatabase method to open the database of your choice

call OpenDatabase(serverName, dbName) 'This will open the database to the view
last viewed by the user

'call OpenDatabase(serverName, dbName, "viewName") 'will Opnen the database to
the view that you want them to see

This was first published in November 2000

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.