Database has not been opened yet

Hi All,I wrote this following script to copy a mail database to a another location and delete the perticular database from the server. it gives a error message “database CN=domino/0=Dev!!mail\it\tuser.nsf has not been opened yet”

i changed the ServerNm to db.server still not working…please help me this is very urgent…

Regards

Shana

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim session As New NotesSession

Dim dbMail As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim Rs As Notesdocument

Dim Comdat As Variant

Set db = session.CurrentDatabase

Set uidoc=workspace.currentdocument

Set doc= uidoc.Document

Dim collection As NotesDocumentCollection

Dim subject As String

Dim mail As String

'ServerNm=doc.ServerNam(0)

ServerNm=db.server

Set dbMail = New NotesDatabase( ServerNm, “names.nsf” )

key=doc.M_AddName(0)

Rdb=doc.M_DB(0)+“.nsf”

Set view = dbMail.GetView( “MAILREMOVE_View” )

Set Rs = view.GetDocumentByKey( Key)

Dim Maildoc As NotesDocument

Set Maildoc = New NotesDocument ( dbMail ) 'create new doc

Dim boxType As Long, answer As Integer

boxType& = MB_YESNO + MB_ICONQUESTION

answer% = Messagebox(“Do you want to Remove “+key+” Mail Details from server ?”, boxType&, _

“Continue?”)

If answer% =“7” Then

Exit Sub

Elseif answer% =“6” Then

Dim archiveDb As New NotesDatabase(ServerNm,"")

archiveFile$ = "backup" & Rdb

Dim dbRem As New NotesDatabase(ServerNm,Rdb )

If (Not(archiveDb.Open(ServerNm,archiveFile$))) Then

'ss=archiveDb.Server

Set archiveDb = dbRem.CreateCopy(ServerNm,archiveFile$ )

End If

Set collection = dbRem.AllDocuments

Dim doc1 As NotesDocument

Set doc1 = collection.GetFirstDocument()

While Not(doc1 Is Nothing)

Call doc1.CopyToDatabase( archiveDb )

Set doc1 = collection.GetNextDocument(doc1)

Wend

Call dbRem.Remove

Rs.Remove(True)

subject = “Resigned Employee Email Removal Process - Mail Details have been Removed”

mail = “This is to inform you that " + doc.M_EmpName(0) + " (Employee No " +doc.M_EmpNo(0)+”) 's Email Details have been removed "

doc.Remarks = "Requested by “+ doc.M_Created(0) + " On” + Str(Date) + " "+ Str(Time)

Call MailSend(doc.M_Created, “”, subject, mail, doc)

doc.curr_appr_no =3

doc.status=“Completed”

'Comdat=Evaluate(“@Now([ServerTime] : [LocalTimeOnError];ServerNm )”)

’ Comdat=newdoc.Created

doc.M_DateC=Now()

doc.M_Del="Completed "

doc.SaveOptions =1

Call doc.save(True, False)

Msgbox “Mail Details have been deleted and confirmation sent to”+" “+doc.M_Created(0)+”! " , 64,“Confirmation”

Call uidoc.close

End If

Subject: Database has not been opened yet

Hi Shana, nothing seems wrong here but u can try by replacing line “Set dbMail = New NotesDatabase( ServerNm, “names.nsf” )”

with

Dim db As New NotesDatabase (“”, “”)

db.Open “ServerName”, “Database.nsf”.

This way it always works but the one u has used may not open database in some situations.

:slight_smile:

Subject: RE: Database has not been opened yet

Thanks amitranjan…i think this is authority problem…i use this script to delete mail files from the server. But i use administrator authority to do this. I manage to do this manually…can you please tell me how to do thisthanks again

shana