This function is used to get a database. This allows one line of code to be used to get and verify the user can open the database. As a function it also allows reuse.
It combines GetDatabase and db.Open and returns the database object if successful. If any tests fail or the user has no access to open, it fails nicely via the Resume FExit and the function returns nothing.
Function DoOpenDb(s As NotesSession, svrnm As String, dbnm As String, debugmode As String) As NotesDatabase
' gets a database and opens it, if opens successfully, returns db, otherwise it returns nothing
Dim aDb As NotesDatabase ' database at server, svrnm, and path, dbnm
On Error Goto FErrorHandler
If (s Is Nothing) Then
If (debugmode="1") Then
Print "(DoOpenDb) No session. Canceled db open."
End If
Set DoOpenDb = Nothing
Exit Function
End If
Set aDb = s.GetDatabase(svrnm, dbnm, False)
If (aDb Is Nothing) Then
If (debugmode="1") Then
Print "(DoOpenDb) No db return for: " & svrnm & " : " & dbnm & "."
End If
Set DoOpenDb = Nothing
Exit Function
End If
' should auto opened if have access
' try to explicitly open db (if not, most likely we will die to errorhander)
If Not (aDb.IsOpen) Then
If (debugmode="1") Then
Print "(DoOpenDb) Db, " & svrnm & " : " & dbnm & ", not open, attempting explicit open."
End If
Call aDb.Open(svrnm, dbnm)
End If
If Not (aDb.IsOpen) Then
' set to nothing, no sense returning it if cannot use it
If (debugmode="1") Then
Print "(DoOpenDb) Db, " & svrnm & " : " & dbnm & ", still not open, return nothing."
End If
Set aDb = Nothing
Set DoOpenDb = Nothing
Exit Function
End If
' have db and db is open ,return it
Set DoOpenDb = aDb
FExit:
Exit Function
FErrorHandler:
If (debugmode="1") Then
Print "(DoOpenDb) Error opening: " & svrnm & " : " & dbnm & ". Error: " & Cstr(Err) & " " & Error$ & ", on line: " & Cstr(Erl) & "."
End If
Resume FExit
End Function
previous page
|