Subject: working example – Create Database programaticaly !!! plz advise
Option PublicOption Explicit
Dim curDB As NotesDatabase
Dim readDB As NotesDatabase
Dim newDB As NotesDatabase, newDBName As String
Dim dbList List As String
Dim FilePath As String
Sub Initialize
' this agent makes local replicas of databases on a scheduled basis
' run on server where we have lotsa space
' the extension of the new file has a timestamp after ".NSF" -- Domino will ignore it
%REM
This agent successfully makes replica copies of databases, putting them in a directory outside the DATA directory.
Unfortunately, the indexer updates all the views one time. It may time-out when copying very large databases.
09/15/2002 02:37:51 AM AMgr: Start executing agent ‘Duplicator’ in ‘Duplicator.nsf’ by Executive ‘2’
…
%END REM
Dim sess As New NotesSession
On Error Goto ProcessError
Set sess = New NotesSession
Set curDB = sess.CurrentDatabase
' --- put as many list entries here as you want to have databases copied ---
dbList( "names" ) = "names.nsf"
’ x dbList( “tel” ) = “telephone.nsf”
’ x dbList( “disc” ) = “discussion.nsf”
FilePath = "C:\DBCopies\" ' copy to this subdirectory
Forall dbName In dbList
Set readDB = New NotesDatabase( curDB.Server, dbName )
If readDB Is Nothing Then Error 999, "cannot open source database " & dbName ' raise an error
newDBName = FilePath & dbName & "_" & GetTimeStamp ' fullpathname of backup file
Print " " & dbName & " being copied to " & newDBName
Set newDB = readDB.CreateReplica( "", newDBName ) ' create new local replica for backup
Print newDBName & " copy done"
Call SendMail( newDBName )
End Forall
Exit Sub
ProcessError:
Print "Error: " & Error$ & " err:" & Err() & " line:" & Erl()
Close
Beep
Exit Sub
End Sub
Function GetTimeStamp As String
' this function returns a time stamp in the following format:
' "12311259" if now is Dec. 31, 12:59
Dim sMo As String, sDa As String, sHo As String, sMi As String
Dim dNow As Variant
On Error Goto SubError
dNow = Now()
sMo = Month( dNow )
If Len( sMo ) = 1 Then sMo = "0" & sMo
sDa = Day( dNow )
If Len( sDa ) = 1 Then sDa = "0" & sDa
sHo = Hour( dNow )
If Len( sHo ) = 1 Then sHo = "0" & sHo
sMi = Minute( dNow )
If Len( sMi ) = 1 Then sMi = "0" & sMi
GetTimeStamp = sMo & sDa & sHo & sMi
Exit Function
SubError:
Print "GetTimeStamp Error: " & Error$ & " err:" & Err() & " line:" & Erl()
Close
Beep
End ' stop with no return
End Function
Sub SendMail( sFileName As String )
Dim emailDoc As NotesDocument
On Error Goto SubError
Dim sAddressees(1) As String
sAddressees(0) = "somename1"
sAddressees(1) = "Doug Jamieson"
Set emailDoc = curDB.CreateDocument
eMailDoc.Form = "Memo"
eMailDoc.Principal = "Duplicator Agent"
eMailDoc.ReplyTo = eMailDoc.Principal(0)
emailDoc.Subject = "notification of new replica on " & curDB.Server
eMailDoc.Body = "A new replica (" & sFileName & ") was created." & Chr(10) & Chr(10) _
& "This agent was run from:" & Chr(10) _
& " " & curDB.Filepath & " " & curDB.Title
Call emailDoc.Send( False, sAddressees )
Exit Sub
SubError:
Print "SendMail " & Error$ & " err:" & Err() & " line:" & Erl()
Close
Beep
End ' stop -- don't just exit the subroutine
End Sub