1
votes

Hello i wrote this code (copying from sites i found online) to find emails in my Inbox view of lotus notes and save the attachments. What i cannot do is to find the docs with the subject i need. The collection is not populated. Where am i wrong? Thanks.

Sub Initialize
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtitem As Variant
Dim filename As Variant

Const DIR_NOT_FOUND = 76
Dim i As Integer
Dim strname As String
Dim view As NotesView
Dim myArray (1 To 2) As String
myArray (1) = "DataToBeSaved"
myArray (2) = "DataToBeSaved"

Set db = sess.currentdatabase
Set view = db.GetView("($Inbox)" )

Set coll = view.GetAllDocumentsByKey(myArray,False)
Set doc = coll.GetFirstDocument()

While Not doc Is Nothing
    Set rtitem = doc.GetFirstItem("Body")
    If Not rtitem Is Nothing Then
        If ( rtitem.Type = RICHTEXT ) Then
            If Isempty(rtitem.EmbeddedObjects) = False Then
                Forall o In rtitem.EmbeddedObjects
                    If ( o.Type = EMBED_ATTACHMENT ) Then
                        filename = Evaluate("@AttachmentNames", doc)
                        'For i = 0 To Ubound(filename)
                        If (filename(i)="query nas.txt") Then
                            strname = Replace(filename(i), "/", "-")
                            On Error DIR_NOT_FOUND Resume Next
                            Call o.ExtractFile( "\\rflenas1.rfle.roto-frank.com\RFIB\LOTUSPROVA\" & strname )
                        End If                          
                        'Next
                        doc.fieldname = ""
                        Call doc.Save( True, True )
                    End If
                End Forall
            End If
        End If
    End If
    Set doc = coll.getnextdocument(doc)
Wend

End Sub

1
You need to add a check for doc.Subject(0) = "SUBJECT YOU WANT TO FIND". - Rob Mason
So i don't have to use GetAllDocumentsByKey? So, What's the key? - Filippo
doc.Subject does not exists in my Lotus - Filippo
After your While doc is not Nothing add if doc.subject(0) = "SUBJECT TO MATCH" then and then put end if before set doc = coll.getnextdocument(doc). Explanation: doc.subject(0) means get the string value of the subject field in the doc - Rob Mason
Thanks, it works :) - Filippo

1 Answers

1
votes

You need to wrap your logic in a loop like this. It will loop round all of the documents in your inbox and if the subejct matches, it will do whatever you want to put in the "Do something with the doc" area.

set doc = view.getfirstdocument
while not doc is nothing
    if doc.subject(0) = "THE SUBJECT I WANT TO FIND" then
    'Do something with the doc
end if
    set doc = view.getnextdocument(doc)
Wend

You will no longer need the coll