Option Public
Option Declare
Dim outStream As NotesStream
Dim linecount As Integer
Sub Initialize()
Dim session As New NotesSession
Dim db As NotesDatabase
Dim parmdb As NotesDatabase
Dim parmview As NotesView
Dim view As NotesView
Dim doc As NotesDocument
Dim olddoc As NotesDocument
Dim iter As Integer
Dim outPath As String
Const filename = "export.csv"
Const filepath = "D:\"
Const file_encoding = "UTF-8"
Const exportView = "FileData"
Set db = session.Currentdatabase
outPath = filepath & filename
Set outStream = session.CreateStream
If Not outStream.Open(outPath, file_encoding) Then
Print "ERROR : cannot open file at " & outpath
Exit Sub
End If
Set view = db.Getview(exportView)
Set doc = view.Getfirstdocument()
iter = 0
linecount = 0
Do While Not(doc Is Nothing)
If Not(doc.Hasitem("flatfiledate")) Then
doc.flatfiledate = Now
iter = iter + 1
If doc.Hasitem("body")then
Call createFlatData(doc)
End If
Call doc.save(False,False,False)
End If
Set olddoc = doc
Set doc = view.Getnextdocument(olddoc)
Delete olddoc
Loop
Call outStream.Close()
Print "wrote " & linecount & " lines"
End Sub
Function formatDate(wdate As String) As String
Dim docdate As NotesDateTime
Dim result As String
Dim w As String
Set docdate = New NotesDateTime(wdate)
result = Year(docdate.Dateonly)
w = "0" & Month(docdate.Dateonly)
w = Right(w,2)
result = result & w
w = "0" & day(docdate.Dateonly)
w = Right(w,2)
result = result & w
formatDate = result
End Function
Sub createFlatData(doc As NotesDocument)
Dim eline As String
Dim sline As String
Dim notesdbname As String
Dim username As String
Dim eventID As String
Dim intro As Integer
Dim middle As Integer
Const sep = ","
eline = ""
sline = doc.fieldname(0)
eline = sline
sline = formatDate(doc.datefield(0))
eline = eline & sep & sline
etc...
'committing to file
Call outStream.Writetext(eline, EOL_CRLF)'EOL_CRLF = 0 for return+feed
linecount = linecount + 1
End Sub