Solved

VBA Read Lotus Notes And Then Mark As Read

Posted on 2012-04-04
10
1,973 Views
Last Modified: 2013-12-18
So I have some code that takes a Lotus Notes Folder and reads it's contents and dumps it into a table. However, I would like two things to happen:

1) It only reads unread mail
2) After reading, marks it as read so that next time it skips it.

Here is my code:

  Dim sess As Object, db As Object, folder As Object, dc As Object, docMemo As Object, docNext As Object
  Dim memoSenders As Variant
  Dim mailServer As String, mailFile As String, folderName As String, todayDate As String, memoSubject As String, memoDate As String
  Dim TempRst As DAO.Recordset
  Dim rst As DAO.Recordset
  Set TempRst = CurrentDb.OpenRecordset("tbl_LotusNotes")
  DoCmd.SetWarnings False
  DoCmd.RunSQL "Delete * from tbl_LotusNotes"
  DoCmd.SetWarnings True
  folderName = ("Deviations")
  
  Set sess = CreateObject("Lotus.NotesSession")
  sess.Initialize ("mypassword")



  mailServer = "mailserver"
  'MsgBox mailServer
  mailFile = "mailfile.nsf"
  'MsgBox mailFile
  Set db = sess.GetDatabase(mailServer, mailFile, False)
  Set folder = db.GetView(folderName)
  todayDate = Format(Now, "MM/DD/YYYY")
  
  Set doc = folder.GetFirstDocument
  Do Until doc Is Nothing
    Set docNext = folder.GetNextDocument(doc)
    
    
    memoSubject = doc.GETITEMVALUE("Subject")(0)
    memoBody = Left(doc.GETITEMVALUE("Body")(0), 7)
    
    '**********************************************
    Dim Email As String
    Email = doc.GETITEMVALUE("Body")(0)
    
    If Email Like "*@*" Then
    
    Dim Pos As Integer ' @ position
'If Not EmailOK(Email) Then Exit Function ' if not valid address, exit
    Pos = InStr(1, Email, "@") ' get @ position

    EmailPart1 = Left$(Email, Pos - 1) ' return user name

    EmailPart = Right$(Email, Len(Email) - Pos) ' return domain
'
'    MsgBox EmailPart1
'    MsgBox EmailPart
    Else
    EmailPart1 = memoBody
    End If
    

    
    
    '**********************************************
    
    
    
    
    
    
    
    
    If (memoSubject Like "*") Then
      memoDate = Right(memoSubject, Len(memoSubject) - 4)
      If (todayDate <> memoDate) Then
        memoSenders = doc.GETITEMVALUE("From")
        nStr = memoSubject
        For X = 1 To Len(nStr)
            If IsNumeric(Mid(nStr, X, 1)) = True Then
                nNum = nNum & Mid(nStr, X, 1)
            End If
                
            Next X
            For Each memosender In memoSenders
            

            s = memosender

            k = Mid(s, InStr(s, "=") + 1, InStr(s, "/") - 1 - InStr(s, "="))
           
            With TempRst
         
                .AddNew
                !from = k
                !Number = nNum
                !Subject = nNum
                !Reply = memoBody
                !Body = memoBody
                !comment1 = EmailPart1
                !comment2 = EmailPart
                .Update
                nNum = ""
            End With

            Next memosender
    
'

        End If
    
    
    End If
    Set doc = docNext
  Loop

Open in new window


Thanks for any help you can give me on this. It's frustrating me.
0
Comment
Question by:G Scott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
10 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37809963
From the Help:

MarkAllRead method  

Marks all of the documents in a collection as read.
Note  This method is new with Release 8.

Defined in
      NotesViewEntryCollection
Syntax
      Call notesViewEntryCollection.MarkAllRead( [username] )
Parameters
      username
      String. Optional. If present, the method marks all of the documents in the collection as read on behalf of the given name. If omitted, the method marks all of the documents in the collection as read on behalf of the current user ID.
0
 
LVL 17

Expert Comment

by:fgrushevsky
ID: 37839858
If you are using a Notes folder (ad-hoc) and not a View then you can just remove document from a folder (or move it into another folder).
This way next time you run the code the processed documents will not be in the folder, so they will not be processed again

Use
Call Doc.RemoveFromFolder( folderName )
 
to remove document from folder
and Call Doc.PutInFolder( anotherfoldername , False )
if you want to keep processed documents in AnotherFoldername for the record
0
 
LVL 13

Accepted Solution

by:
JonNorman earned 500 total points
ID: 37891897
There is an undocument LotusScript method in the NotesDatabase object - db.GetAllUnreadDocuments, You could check to see if your doc is in this collection.

This is how you would do it in pure LotusScript (hopefully you would be able to do similar:

  Dim unread as NotesDocumentCollection
  Set unread = db.GetAllUnreadDocuments
  Set doc = folder.GetFirstDocument
  Do Until doc Is Nothing
    Set docNext = folder.GetNextDocument(doc)
    If Not unread.getDocument(doc) is Nothing then
      'You want to process this one.
...

Then once you have processed the doc you can do doc.MarkRead.

Good Luck!

Jon
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37892215
0
 
LVL 13

Expert Comment

by:JonNorman
ID: 37892530
yes, undocumented, undocument was a typo - tooo used to typing document!!!!
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37892563
Click the link in my previous comment ;-))
0
 
LVL 13

Expert Comment

by:JonNorman
ID: 37892578
Wow they've documented it now!
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37892668
:-)) And welcome to EE's Notes zones!
0
 
LVL 13

Expert Comment

by:JonNorman
ID: 37897096
Thanks, good to be here.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question