We help IT Professionals succeed at work.

How do you loop thru a Lotus Notes Folder and extract attachments via a VBA module in MS Access

pbo1
pbo1 asked
on
I have a folder in Lotus Notes 6.5 called "que".  I also have a MS Access 2003 database.  Within MS Access 2003 (VB module) I want to

1. Loop thru my Lotus Notes "que" folder and save off attachments (note there could be multiple attachments within an email) to C:/My Documents/To Be Processed/.  
2.Once I save the attachments I want to move the email from the "que" folder to a folder called "processed".
Comment
Watch Question

The best is to create a Lotus Notes Agent that do the job and just call in VBA the agent.
Dim session As Object
We declare db as an object which references NotesDatabase.
Dim db As Object
We declare view as an object which references NotesView.
Dim view As Object
We get the reference to NotesSession by using the CreateObject function of
Visual Basic, and store it in session.
Set session = CreateObject ("Notes.NotesSession")
We get the reference to NotesDatabase using the GetDatabase method of
NotesSession, and store it in db.
Set db = session.GetDatabase("","test.nsf")
dim agent as object
set agent  db.getAgent("extact_attach");
call agent.run

Author

Commented:
how do I create a lotus notes agent...is this outside of the vba module ?  I create the notes agent within notes ?
concerning the Lotus Notes Agent this is a skeletton

Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim vc As NotesViewEntryCollection
Set db = session.CurrentDatabase
Set view = db.GetView("que")
view.AutoUpdate = False
Dim doc As NotesDocument
Dim rtitem As Variant
Dim fileCount As Integer
fileCount = 0    
set doc=view.getfirstdocument
while not doc  is nothing
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
  Forall o In rtitem.EmbeddedObjects
    If ( o.Type = EMBED_ATTACHMENT ) Then
      fileCount = fileCount + 1
      Call o.ExtractFile _
      ( "C:/My Documents/To Be Processed/" )
' no need I think      Call o.Remove
' no need I think      Call doc.Save( True, True )
    End If
  End Forall
End If
set entry=view.GetNextdocument(doc)
wend

Set vc = view.AllEntries
Call vc.PutAllInFolder("processed")
how do I create a lotus notes agent...is this outside of the vba module ?  I create the notes agent within notes ?
>> yes in the "designer"
you can enter directly using in the menu "Create/Agent"

Author

Commented:
cool manu..i give it a try and let you know outcome...

Author

Commented:
ok.. i found it under create agent, but it does not seem too intuitive in terms of what I need to do/options.  Any suggested links for creating agents ?
Notes / Domino is a whole environment.... so of course I can send you to the doc:
press ctrl+O and in the HELP directory you will find the Help Designer with all the class and so on....
concerning a "one shot" agent creation,
you can post screen shoot and questions.

Author

Commented:
ok..thanks for that offer..before I get started I want to ensure that when I create this agent I am only effecting my mailboxes..how do I confirm I only am effecting my inbox.  It would not be good if I effected someone else's mailbox..
the agent is using session.CurrentDatabase
meaning will act on the current database, since this agent doesnt open other DB it CAN'T affecte someone else mailbox.
on VBA part since you open YOUR mailbox (BTW update the Set db = session.GetDatabase("","test.nsf") to your data)
if anyway you open from VBA a collegue DB (if you've have access) VBA won't find the agent there so you would get an error.

Author

Commented:
Excellent !
Thanks, and have fun with Lotus Notes Domino!
best regards,

Emmanuel Gleizer