Search all docs in view, output to text file

This script will search a specific view and check all documents to see if a specific form type exists for each staff serial number. Output is sent to a text file on the root of the hard drive
Lotus Notes View • LotusScript


Sub Initialize
     
'Declare all variables
     Dim ss As New NotesSession 
     Dim db As NotesDatabase 
     Dim view As NotesView 
     Dim doc As NotesDocument 
     Dim filenum1 As Integer
     Dim serial1 As String 
     Dim serial2 As String 
     Dim serial As String
     Dim fname As String
     Dim lname As String
     Dim hasdwages As String
     
'Set all default variables
     Set db = ss.CurrentDatabase
     Set view = db.GetView("1. Compensation\By Last Name")        'Sets the specific view to scan
     Set doc = view.GetFirstDocument 
     hasdwages = "No"
     serial = doc.serial(0)
     serial1 = doc.serial(0)            'Handle #1
     serial2 = doc.Serial(0)            'Handle #2
     lname = doc.LName(0)          
     fname = doc.FName(0)       
     
'Create and open text file for append on the local hard drive     
     filenum1 =Freefile
     Open "c:\MsDWages.txt" For Append As filenum1
     
'Prompt the user with a status
     Print "Identifying staff who do not have Detail Wages Breakdown - Domestic..." 
     
'Begins the loop, starting with the first doc in the view and proceeding to the last
     Do While Not(doc Is Nothing)                   
          
          serial2 = doc.Serial(0)    
          
          If serial2 = serial1 Then
               If hasdwages = "No" Then
                    If doc.form(0) = "DWages" Then
                         hasdwages="Yes"
                    Else
                         hasdwages="No"
                    End If
               End If
               Set doc = view.GetNextDocument(doc) 
          Else
               If hasdwages = "No" Then
                    Write #filenum1 , LName,FName, Serial
                    serial1 = doc.serial(0)
                    lname = doc.LName(0) 
                    fname = doc.FName(0) 
                    serial = doc.serial(0)  
                    If doc.Form(0) = "DWages" Then
                         hasdwages="Yes"
                    Else
                         hasdwages="No"
                    End If
               Else
                    serial1 = doc.serial(0)
                    lname = doc.LName(0) 
                    fname = doc.FName(0) 
                    serial = doc.serial(0)  
                    If doc.Form(0) = "DWages" Then
                         hasdwages="Yes"
                    Else
                         hasdwages="No"
                    End If
               End If
          End If     
     Loop 
     
'Determines if the last doc in the view needs to have an entry made in the text file before closing     
     If hasdwages = "No" Then
          Write #filenum1 , LName,FName, Serial
     End If
     
'Closes the text file
     Close filenum1
     
'Notifies the user of competion and the file path
     Messagebox"The results have been written to:" & Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10) & "C:\MsDWages.txt",0+64,"Finsihed!"
     
End Sub

Posted by fbrefere001 on Monday February 26, 2001