"Smart" Database Open Button

This code will open a specified database on a server for a user. More
importantly, it will do so even if the user cannot immediately connect to the
server - by creating a connection doc to the server if needed. The code can
open the Db to the default view, or to a specified view, or open a specific doc
in a view, or compose a document in the database - depending on how the
parameters are set. This is version 1.0, if there are problems, E-mail me and
I will see about fixing them and release a new version...
Option Declare

Sub Click(Source As Button)
On Error Goto GeneralError
Dim Server As String, PathName As String, IPAddress As String, View As String,
Document As String
Dim ErrorNames( 2 ) As String
Dim AddToWorkspace As Variant, ComposeDoc As Variant
' Change Server to the name of the server you want to connect to.
' Change PathName to the file-path of the database.
' Change IPAddress to the address of the server you want to connect to. (Only
used if the public NAB
' cannot be opened for unknown reasons)
' Change View to the view to open, otherwise the db will open to the default
' Change Document only if View is specified, and a key search for that doc
will open that doc
' instead of the view.
' Change AddToWorkspace to indicate if you want to add the icon (true) or not
' Change CompseDoc to compose the doc specified in Document.
Server$ = "AnyServer/SERVER/Company"
PathName$ = "names.nsf"
IPAddress$ = ""
View$ = "People"
Document$ = "Fredette , Robert"
AddToWorkspace = True
ComposeDoc = False
ErrorNames$( 0 ) = "First Person To Notify in Case of Error/OU/Company"
ErrorNames$( 1 ) = "Second Person/OU/Company"
ErrorNames$( 2 ) = "Third etc. User group if needed"

Call Main( Server$, PathName$, IPAddress$, View$, Document$, _
AddToWorkspace, ComposeDoc, ErrorNames$ )
Exit Sub
Call OpenError( Error$() )
Exit Sub
End Sub
Sub MakeConnection( Server As String, IPAddress As String )
' This routine will create a connection document to the server.
Dim WS As New NotesUIWorkspace, UIDoc As NotesUIDocument, s As New
NotesSession, Doc As NotesDocument
Dim LNAB As NotesDatabase, Conn_Doc As NotesDocument, LU_View As NotesView,
Count As Integer
Dim Nom As NotesName, days( 6 ) As String, PNAB As NotesDatabase, PDoc As
Dim Pview As NotesView, IPTemp As String, tmpItem As NotesItem
Dim dr As NotesDateRange, i As Integer, Lview As NotesView

Set UIDoc = WS.CurrentDocument
Set Doc = UIDoc.Document
Set Nom = New NotesName( Server$ )

Forall q In s.Addressbooks
If q.IsPrivateAddressBook Then Set LNAB = q
If q.IsPublicAddressBook Then
If Ucase$( q.FilePath ) = "NAMES.NSF" Then
' Just in case there are cascaded address books...
Set PNAB = q
End If
End If
End Forall
Call LNAB.Open( "","" ) 'Open the Local NAB
If Not LNAB.Isopen Then
Messagebox "Can't Open the Local Address Book." & Chr(13) & "Call local
support." , 48, "Error"
Exit Sub
End If
Set LU_View = LNAB.GetView( "Connections" )
If LU_View Is Nothing Then
Messagebox "Can't get Connections View." & Chr(13) & "Call local support." ,
48 , "Error"
Exit Sub
End If
Set Lview = LNAB.GetView( "($Connections)" )
' This is the hidden view we need to update after making the connection...
If Lview Is Nothing Then
Messagebox "Can't get Hidden Connections View." & Chr(13) & "Call local
support." , 48 , "Error"
Exit Sub
End If
' Now open the Public NAB if we can, to get the IP address (updated from the
one provided)
If Not ( PNAB Is Nothing ) Then
Print "Looking for Server Address in Public Address Book. Please wait..."
Call PNAB.Open( "", "" )
If PNAB.IsOpen Then
' Try opening the Servers view
Print "Looking for Server Address in Public Address Book. Please wait..."
Set Pview = PNAB.GetView( "($ServerAccess)" )
Print "Looking for Server Address in Public Address Book. Please wait..."
If Not ( Pview Is Nothing ) Then
' Try to find the server in the list...
Set Pdoc = Pview.GetDocumentByKey( Nom.Canonical )
If Not ( Pdoc Is Nothing ) Then
' Use the IP address we just found...
For i = 7 To 0 Step -1
' This will set preference to the NetAddr_0 address...
Set tmpitem = doc.GetFirstItem( "NetAddr_" & Cstr( i ) )
If Not (tmpItem Is Nothing ) Then
IPTemp$ = tmpitem.Values( 0 )
If Instr( 1, IPTemp$, ".", 1 ) > 0 Then
IPAddress$ = IPTemp$&LTWHA

Dig Deeper on Domino Resources - Part 2

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...