Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA Read Lotus Notes And Then Mark As Read

Posted on 2012-04-04
10
Medium Priority
?
2,100 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 1500 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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.

610 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