I am having a problem with the UIDB.Close method not working in an application I am working on.
The script in located in the Database Script in the POSTOPEN event and is used to direct users to their correct copy of this database.
If a user with a home server of B opens the database on server A, the script opens the correct DB on server B for them.
This functionality works fine, however I cannot get the original database to close. I have scanned back through all the forums for all releases and nothing I found there has had any effect. I am sure I am not the first person to want to do this, so can anyone give me an idea how to make this happen?
If you want to close the database that is being opened, be sure to close it before you open the second database. Otherwise the new DB will become the uidb
Here is the code, but when I tried moving the close before the database open, it throws a “context” error.
This is the Postopen event in the Database Script.
Thanks
Sub Postopen(Source As Notesuidatabase)
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim curdb As NotesDatabase
Dim user As String
Dim userServer As String
Dim curServer As String
Dim curPath As String
Dim closeIT As Boolean
Set curDB = Source.Database
curPath = curdb.FilePath
curServer = curdb.Server
closeIT = False
user = session.UserName
Dim uiview As NotesUIView
Set uiview = ws.CurrentView
Dim direct As NotesDirectory
Dim nav As NotesDirectoryNavigator
Dim value As Variant
Set direct = session.getDirectory(curServer)
Set nav = direct.LookupNames("$Users",user,"Mailserver")
value = nav.GetFirstItemValue
userServer = Ucase(Cstr(value(0)))
If userServer <> Ucase(curServer) Then
Print "Error"
Call session.SetEnvironmentVar( "BWF2DbSetup", "" )
Call ws.OpenDatabase( userServer, curPath, "", "", False, False )
Call curDB.close()
End If
I’m not sure what the issue could be. Are you sure your server and database variables are set?
The below code works fine for me.
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim curdb As NotesDatabase
Dim user As String
Dim userServer As String
Dim curServer As String
Dim curPath As String
Dim closeIT As Boolean
Set curDB = Source.Database
curPath = curdb.FilePath
curServer = curdb.Server
closeIT = False
user = session.UserName
Dim uiview As NotesUIView
Set uiview = ws.CurrentView
Dim direct As NotesDirectory
Dim nav As NotesDirectoryNavigator
Dim value As Variant
Set direct = session.getDirectory(curServer)
Set nav = direct.LookupNames("$Users",user,"Mailserver")
value = nav.GetFirstItemValue
userServer = Ucase(Cstr(value(0)))
'note that I changed this line because I’m running on my server
If userServer = Ucase(curServer) Then
Print "Error"
Call session.SetEnvironmentVar( "BWF2DbSetup", "" )
Call source.close()
Call ws.OpenDatabase( "serverName", "database", "", "", False, False )
End If