Loop skips in Lotus Notes view

Tiger955

Registered User.
Local time
Today, 21:29
Joined
Sep 13, 2013
Messages
140
Hi,
I have a problem whithout a explanation for it and no solution, so please help me with it:

I am looping through a Lotus Notes view through mails which comes with standardized content from our homepage.

Some of them have one or more attachments, some mails do not have attachments. I loop through the view, read the content, write the content in a table, extract all the attachments (if there are some) and remove the mail from view this into another view.

The loops runs through without error, but is skips the mails without attachments, so that after the "first loop" all mails without attachments remain in the view, whereas all with attachments have been processed accordingly.

With another start of the function all the mails WITHOUT attachments are processed accordingly as well.

This is not logic for me, as all code I found on the web looks like this:

*************
Do While Not LNDoc Is Nothing

Set NxtDoc = LNView.GetNextDocument(LNDoc)
...
'check if Attachments are in the mail !!!!!!

If LNDoc.HasEmbedded Then <----
For Each LNAttachment In LNItem.EmbeddedObjects
LNAttachment.ExtractFile (CurrentProject.Path & "\" & LNAttachment.Name)
DoEvents
Next
End If

'delete mail from this view
Call LNDoc.RemoveFromFolder("Inputbox$")

'move into another view
Call LNDoc.PutInFolder("Backup", False)

'load next mail
Set LNDoc = NxtDoc
Loop
******************

Any idea?

Thanks
Michael
 
Hi JHB,

I did not find the reason for it, but I could limit it to the specific type of mail from our homepage.

Meanwhile I am looping through two different folders, one has standardized mails form our homepage (with or without attachements) and the other folder includes also mails (with or without attachements) from another homepage.

The problem is only on the mails from our homepage.

If I use the code in my thread without extracting any attachment then the code loops through without skipping any mail.

Now I assume, that is has something to do with the attachments or with the entry in a mail, if there is NO attachment.

Here is the complete code of the procedure:
It is very long, because i read out values from the mail, write it in tbls then I extract the attachments, rename then, move them, reply automatically to the mail read, etc. All things which works, exept the skipping within the view.

BTW there are to many declarations of previous trials which I did not clean up yet.

Code:
[SIZE=3][FONT=Calibri]Public Function BewerbungenDurchlaufViewHP()[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Const EMBED_ATTACHMENT As Long = 1454[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Const OrdnerKuerzel As String = "HP[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Const LNOrdnername As String = "Bewerbungen Homepage"[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Const LNBackupOrdner As String = "Bewerbungen beantwortet"[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim objNotes As Object[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim LNdb As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim UserName As String 'Der Benutzername[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim MailDbName As String 'Der Datenbankname[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNCollection As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNView As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNDoc As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim NxtDoc As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNItem As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNItemDatum As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNItemAbsender As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNItemVeranstaltungsnummer As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNItemVeranstaltungsText As Object[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim strMailBody As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim dteEmpfangsdatum As Date[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strName As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strAdresse As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strTelefonnummer As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strAttachment As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim lngBewID As Long[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strNewAttachmentName As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strTmpFileUndPfad As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strTmpPDFFilename As String[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim strMail As String 'Antworttextstring[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strMessageText As String 'die ganze Message[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strSQLCodeAendern As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strProtokoll As String[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim strStatus As String[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim i As Integer[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim iAttach As Integer[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim strSubject As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNWorkspace As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim LNAttachment As Variant[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim Workspace As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim uidoc As Object[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim strNSF As String[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim rs As Recordset, rs1 As Recordset, rs2 As Recordset, rs3 As Recordset, rs4 As Recordset, rs5 As Recordset, rs6 As Recordset[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim vbody As Variant, z As Integer, Feldname As String, Zeile As String[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Dim Mailadresse As String[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   Dim iFile As Integer[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]  On Error GoTo ErrHandler[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   'Holen einer aktiven Notessession[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Set objNotes = GetObject("", "Notes.NotesSession")[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   'NSF des aktuellen Users suchen[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   strNSF = DLookup("NSF", "tblUser", "([ID] = " & TempVars!intUser & ")")[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   'Debug.Print strNSF[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Set LNdb = objNotes.GETDATABASE("xxxx", strNSF)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   If Not LNdb.IsOpen Then 'LNdb.OpenDatabase[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]       MsgBox "Bitte öffnen Sie Ihren Lotes Notes Client, damit Mails eingelesen werden können!", vbOKOnly + vbExclamation, "Lotus Notes ist nicht geöffnet!"[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]       Exit Function[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   End If[/FONT][/SIZE]
 
 
[SIZE=3][FONT=Calibri]If Not (LNdb Is Nothing) Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]       'Zugriff des gewünschten Ordners[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]       Set LNView = LNdb.GetView(LNOrdnername)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]       Set LNCollection = LNdb.Search("", Nothing, 0)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]           If Not (LNView Is Nothing) Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                   'Aktualsieren des Views[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                   Call LNView.Refresh[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                   'Jetzt wird die tblBewerbungen geöffnet um einmal alles in eine tbl zu schreiben[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                   Set rs = CurrentDb.OpenRecordset("tblBewerbungen", dbOpenDynaset, dbSeeChanges)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                   'Jetzt wird die tblBewerbungsunterlagen geöffnet um einmal alles in eine tbl zu schreiben[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                   Set rs1 = CurrentDb.OpenRecordset("tblBewerbungsunterlagen", dbOpenDynaset, dbSeeChanges)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                   'Einlesen des ersten Mail-Dokuments[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                   Set LNDoc = LNView.GetFirstDocument[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                   Do While Not LNDoc Is Nothing[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       i = i + 1[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       Set NxtDoc = LNView.GetNextDocument(LNDoc)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       'Empfangsdatum[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       Set LNItem = LNDoc.GetFirstItem("DeliveredDate")[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       dteEmpfangsdatum = Nz(LNItem.Text)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                       Set LNItem = LNDoc.GetFirstItem("Body")[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       strMailBody = Nz(LNItem.Text)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                       'nun werden die Daten in die Tabelle tblBewerbungen geschrieben[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs.AddNew[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("DeliveredDate") = CDate(dteEmpfangsdatum)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("MailBody") = strMailBody[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("RegID") = TempVars!RegID[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("NameBewerber") = fncMemoPartName(strMailBody, OrdnerKuerzel)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("Mail") = fncMemoPartEmail(strMailBody, OrdnerKuerzel)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("Strasse") = fncMemoPartAdresse(strMailBody, OrdnerKuerzel)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("Telefon") = fncMemoPartTelefonnummer(strMailBody, OrdnerKuerzel)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("GebDatum") = CDate(fncMemoPartGebDatum(strMailBody, OrdnerKuerzel))[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs("wie_beworben") = 1 '1:Homepage, 2:andere, 3:Mail[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs.Update[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       rs.Bookmark = rs.LastModified[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                       lngBewID = rs("BewID")[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                       'Prüfen ob Attachments innerhalb der Mail vorhanden sind[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       If LNDoc.hasembedded Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                           For Each LNAttachment In LNItem.EmbeddedObjects[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               iAttach = iAttach + 1[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                                'aus dem Attachment-Namen alle Ziffern entfernen und umbenennen[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                                strTmpFileUndPfad = CurrentProject.Path & "\B" & Format(lngBewID, "0000") & "_ " & BuchstabenExtrahieren2(LeerstellenExtrahieren(LNAttachment.Name))[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               'macht aus 20148111805661VLebenslauf.docx  --> D:\Access-Dateien\SECI\0123_VLebenslauf.docx[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                               If LNAttachment.Type = EMBED_ATTACHMENT Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                                   'zuerst einmal lokal in den Anwendungspfad extrahieren[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                                   LNAttachment.ExtractFile (strTmpFileUndPfad)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                                   'D:\Access-Dateien\SECI\20148111805661VLebenslauf.docx[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                                   DoEvents[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                                   'bißchen warten[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               End If[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                               'dann verschieben[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               Call MoveFile(FilenameOnly(strTmpFileUndPfad), CurrentProject.Path, TempVars!SpeicherpfadContracts & "Bewerbungsunterlagen")[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               'verschiebt von D:\Access-Dateien\SECI\0123_VLebenslauf.pdf --> H:\SECI\Bewerbungsunterlagen\0123_VLebenslauf.pdf[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                               'nun den Speicherpfand der Attachments schreiben[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               rs1.AddNew[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               rs1("BewID") = lngBewID[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               rs1("Anlagepfad") = TempVars!SpeicherpfadContracts & "Bewerbungsunterlagen\" & FilenameOnly(strTmpFileUndPfad)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               rs1("OriginalDocName") = LNAttachment.Name[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                               rs1.Update[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                           Next LNAttachment[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       LNAttachment = ""[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       End If[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                       'Ausgelesen, nun kann Mail gelöscht werden[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       Call LNDoc.RemoveFromFolder(LNOrdnername)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                       'Verschieben in anderen Folder[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       Call LNDoc.PutInFolder(LNBackupOrdner, False)[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                      'Ermitteln des nächsten Mail-Dokuments[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       Set LNDoc = NxtDoc[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                      'jetzt noch ein automatisches Antwortmail senden[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                      strMail = Trim(fncMemoPartEmail(strMailBody, OrdnerKuerzel))[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                      'Standardtext einlesen mit Signatur und versenden[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                      iFile = FreeFile[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                       Open TempVars!SpeicherpfadContracts & "Vorlagen\AntwortBewerbung.txt" For Input As #iFile[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       strMessageText = Input(LOF(iFile), iFile)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       Close #iFile[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                      If Len(strMail) > 4 Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                       Call sendLotusNotesMail("Ihre Bewerbung vom " & dteEmpfangsdatum, "", strMail, strMessageText, True)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]                      End If[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]                   Loop[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]           End If[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]'nun nochmals  View öffnen, um alles als gelesen zu markieren[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Set LNView = LNdb.GetView(LNBackupOrdner)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]'nun alle Mails, die eingelesen wurden als gelesen markieren[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Call LNView.MarkAllRead[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]'Set LNCollection = Nothing[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]   If Err = 0 Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]       MsgBox "Es wurden " & i & " Mails ausgelesen und insgesamt " & iAttach & " Attachments in den Ordner 'Bewerbungsunterlagen' abgespeichert.", vbOKOnly + vbInformation, "Ordner 'Bewerbungen Homapage' durchsucht"[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   End If[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]End If[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]Finally:[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   On Error Resume Next[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Set objNotes = Nothing[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Set LNdb = Nothing[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Set LNView = Nothing[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Set LNItem = Nothing[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Set LNWorkspace = Nothing[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Set LNDoc = Nothing[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]ErrHandler:[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   'MsgBox Err.Description, vbCritical[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]   Resume Finally[/FONT][/SIZE]
 
[SIZE=3][FONT=Calibri]End Function[/FONT][/SIZE]

Hope you find any improvement for my problem.

Thanks
Michael
 
..
The loops runs through without error, ...
You can't really said that because you've an error handling in your code.
Comment out that line and see what happen!
Code:
[SIZE=3][FONT=Calibri]On Error GoTo ErrHandler[/FONT][/SIZE]
Then you looping through all documents in a folder, but I don't like the way you do it, because you remove documents from the folder and I'm not sure the next document really is the next document in the folder.
Code:
[SIZE=3][FONT=Calibri]'Ermitteln des nächsten Mail-Dokuments[/FONT][/SIZE] [SIZE=3][FONT=Calibri] 
  Set LNDoc = NxtDoc[/FONT][/SIZE]
 
I don't use Lotus Notes so I can't advise on what properties or methods to look for but I think JHB is onto something so I'll add some extra comments.

You can't really said that because you've an error handling in your code.
Code:
[SIZE=3][FONT=Calibri]On Error GoTo ErrHandler[/FONT][/SIZE]
... and because you're resuming next, i.e.
Code:
Resume Finally
... that's not a very good error handling technique.

Then you looping through all documents in a folder, but I don't like the way you do it, because you remove documents from the folder and I'm not sure the next document really is the next document in the folder.
Code:
[SIZE=3][FONT=Calibri]'Ermitteln des nächsten Mail-Dokuments[/FONT][/SIZE] [SIZE=3][FONT=Calibri] 
  Set LNDoc = NxtDoc[/FONT][/SIZE]
Go through the entire collection, identify the ones you want to delete and delete after your entire operation. otherwise, you'll probably need to manage the pointers to the next/previous item.
 
Hi both,

It seems that JHB found the reason of the jumps: somehow Lotus gets confused when I delete the mail during the Loop.

within the Loop I now fill a collection, after finishing the loop I move all mails at once in another folder and delete all mails at once from the Inbox folder.

So, my Problem is solved!

Thanks!!
Michael
icon10.gif
 
Good you got it solved, luck with your project. :)
 

Users who are viewing this thread

Back
Top Bottom