Solved

VBA Read Lotus Notes And Then Mark As Read

Posted on 2012-04-04
10
1,896 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now