Reputation: 37
Thanks in advance for any help!
I'm ultimately trying to pull information from specific emails based on subject line. Working up to the problem the below code was a test to pull up a subject line. However it runs through 132 documents without a single subject identified as anything other than blank. Using this same Initialize and GetDatabase method I successfully sent emails through Lotus Notes, so I don't think I'm after the wrong docs somehow. Below code written in VBA through Excel have Lotus Notes 8.5
Anyone see a reason why I would get nothing but blanks going through all of the docs in the Notes Database?
Sub LotusGetView()
Dim Nsess As New NotesSession
Dim Ndb As NotesDatabase
Dim Ndocs As NotesDocumentCollection
Dim Ndoc As NotesDocument, docNext As NotesDocument
Dim c As Long
Dim memSubj As Variant
Nsess.Initialize
Set Ndb = Nsess.GetDatabase("", "names.nsf")
Set Ndocs = Ndb.AllDocuments
c = 1
Set Ndoc = Ndocs.GetFirstDocument
Do Until Ndoc Is Nothing Or c = 1000
Set docNext = Ndocs.GetNextDocument(Ndoc)
memSubj = Ndoc.GetItemValue("Subject")(0)
If memSubj <> "" Then
MsgBox memSubj
End If
Call Ndoc.Remove(True)
Set Ndoc = docNext
c = c + 1
Loop
MsgBox c
End Sub
Upvotes: 0
Views: 407
Reputation: 14628
Your problem is this line:
Set Ndb = Nsess.GetDatabase("", "names.nsf")
You are opening names.nsf. That is the user's personal address book database. It is not the user's mail database. Your previous work to send mail worked because you don't need to access a mail database to send mail. You can send mail from anywhere. In order to read mail, you have to open the mail database.
The OpenMailDatabase method of the NotesDbDirectory class provides an easy way for you to find and open the current user's mail database.
Upvotes: 1