Getting eMails from .nsf into Access via VBA

Discussion in 'Lotus Notes Programming' started by Andreas Brandmaier, Dec 28, 2004.

  1. Hello everybody,

    I've been trying all day write a small piece of code in VBA that will
    access my personal .nsf file, read out all my mail data (or at least
    sender, subject, send time and body), and then save the information to
    a simple table in an access database . So far, what I've come up with
    seems to loop correctly through my mailbox, yet returns with 2365
    empty records, which is exactly the number of documents in my mailbox.

    To be honest my VBA-skills are quite limited... Any suggestions what
    I've made wrong?

    Thanks for any help!

    Regards,

    Andrew

    --- <snip> ----

    Public Function GetMail() As Boolean
    On Error Resume Next

    Dim DbsChecker As Object
    Dim RecChecker As Object

    Set DbsChecker = OpenDatabase("M:\eMail Wizard.mdb")
    Set RecChecker = DbsChecker.OpenRecordset("tblMailStoreTemp")
    DoEvents

    Dim n_Session As Object
    Dim n_Database As Object
    Dim n_ViewNav As Object
    Dim n_ViewEntry As Object
    Dim n_Document As Object

    Set n_Session = CreateObject("Notes.NotesSession")
    Set n_Database = n_Session.GetDatabase("", "g8307.nsf")

    If n_Database.IsOpen = False Then
    n_Database.OPENMAIL
    End If

    Set n_ViewNav = n_Database.AllDocuments
    Set n_ViewEntry = n_ViewNav.GetFirstDocument()

    Do While Not (n_ViewEntry Is Nothing)

    Set n_Document = n_ViewEntry.Document

    With RecChecker

    .AddNew

    .EnterBlindCopyTo = n_Document.GetItemValue("EnterBlindCopyTo")
    .EnterCopyTo = n_Document.GetItemValue("EnterCopyTo")
    .EnterSendTo = n_Document.GetItemValue("EnterSendTo")
    .WebSubject = n_Document.GetItemValue("WebSubject")
    .BlindCopyTo = n_Document.GetItemValue("BlindCopyTo")
    .CopyTo = n_Document.GetItemValue("CopyTo")
    .Query_String = n_Document.GetItemValue("Query_String")
    .Path_Info = n_Document.GetItemValue("Path_Info")
    .DefaultMailSaveOptions =
    n_Document.GetItemValue("DefaultMailSaveOptions")
    .ENCRYPT = n_Document.GetItemValue("Encrypt")
    .SIGN = n_Document.GetItemValue("Sign")
    .Logo = n_Document.GetItemValue("Logo")
    .AltFrom = n_Document.GetItemValue("AltFrom")
    .Form = n_Document.GetItemValue("Form")
    .Subject = n_Document.GetItemValue("Subject")
    .Body = n_Document.GetItemValue("Body")
    .From = n_Document.GetItemValue("From")
    .CopyTo = n_Document.GetItemValue("CopyTo")
    .DelvDate = n_Document.GetItemValue("DeliveredDate")
    .sendto = n_Document.GetItemValue("SendTo")
    .Update
    DoEvents
    End With

    Set n_ViewEntry = n_ViewNav.GetNextDocument(n_ViewEntry)
    Loop

    GetMail = True

    Set n_ViewEntry = Nothing
    Set n_ViewNav = Nothing
    Set n_View = Nothing
    Set n_Document = Nothing
    Set n_Database = Nothing
    Set n_Session = Nothing

    End Function
     
    Andreas Brandmaier, Dec 28, 2004
    #1
    1. Advertisements

  2. Hello Andreas, first of all you should remove "On Error Resume Next"
    because this will give you a chance to react to error notifications.
    Now this is confusing: n_ViewEntry already is a notes document
    handle, so you must not use "Set n_Document = n_ViewEntry.
    Document" otherwise you'll get back a null pointer. Seems that
    you experimented with a NotesViewEntryCollection before - this
    is different from a NotesDocumentCollection.
    Keep in mind that GetItemValue always returns an array of values.
    But if your "RecChecker" accepts arrays, this is just fine.
     
    Christian Zalto, Jan 2, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.