Tip

Write Out Field Values To A Csv File

This little workhorse takes a view of your choice, an array of field names, and
a filename, then gets the value of those items and writes them to a file in CSV
format. If nothing is found in the view, it returns false.
Enjoy!
Function WriteValuesToFile(viewTarget As NotesView, varFieldNames As
Variant,strFileName As String) As Integer
Dim intFileNum As Integer
Dim intArraySubscript As Integer
Dim vecViewTarget As NotesViewEntryCollection
Dim ventViewTarget As NotesViewEntry
Dim docViewTarget As NotesDocument
Dim strFieldName As String
Const Quote = {"}
Const Delim = {,}
Const EndLine = {;}

Set vecViewTarget = viewTarget.AllEntries

If vecViewTarget.count < 1 Then 'Check for values to retrieve before opening a
file handle

WriteValuesToFile = False
Exit Function

Else
WriteValuesToFile = True
End If

intFileNum = Freefile()

Open strFileName For Output As #intFileNum

Set ventViewTarget = vecViewTarget.GetFirstEntry 'Get 1st entry in view

Do While Not ( ventViewTarget Is Nothing) ' for all the documents in the
view, print out the desired field values to the file
Set docViewTarget = ventViewTarget.Document
strDocRecord = ""
For intArraySubscript = 0 To Ubound(varFieldNames)

strFieldName = varFieldNames(intArraySubscript)

Set itmNeeded = docViewTarget.GetFirstItem(strFieldName)

If strDocRecord = "" Then

strDocRecord = Quote & itmNeeded.text & Quote
Else


strDocRecord =strDocRecord & Delim & Quote & itmNeeded.text & Quote

End If


Next intArraySubscript
strDocRecord =strDocRecord & EndLine 'Here is the whole delimited string to
go on a line in the file
Print #intFileNum, strDocRecord


Set ventViewTarget = vecViewTarget.GetNextEntry(ventViewTarget)
Loop


Close #fileNumInt

End Function

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.