Solved

VBA Read Lotus Notes And Then Mark As Read

Posted on 2012-04-04
10
1,881 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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37892215
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now