Solved

VBA Read Lotus Notes And Then Mark As Read

Posted on 2012-04-04
10
1,947 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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

765 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