Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012

    Unanswered: Word Macro VBA Lotus Domino Error - Notes Error: Database Already Contains a Document

    I am using a Word Template Macro-Enabled document (.dotm) in which the user completes the form, then clicks the Command Button which saves the file, then send a lotus note to a specified address. The code for the saving works great, then I call the email function, and errors at the line to send the document.

    The error is:
    Run-time Error '-2147217504 (80040fa0)':

    Notes Error: Database already contains a document with this ID (UNID).

    Below is the code form the Email Function:

    Public Function SendEmail(strName As String, strFile As String, strPOLICY)

    Dim oDir As Domino.NotesDbDirectory
    Dim oDBase As Domino.NotesDatabase
    Dim oDoc As Domino.NotesDocument
    Dim oRTItem As Domino.NotesRichTextItem
    Dim oRTStyle As Domino.NotesRichTextStyle
    Dim oRTTab As Domino.NotesRichTextTab
    Dim oItem As Domino.NotesForm
    Dim strMailServer As String, strImportance As String

    Dim strTo() As String
    'Dim strCC() As String

    Set oSession = New Domino.NotesSession
    Call oSession.Initialize(MyLnotesPassword)

    ReDim astrTo(0)
    astrTo(0) = strName
    'astrCC(0) = strCarbon

    strMailServer = oSession.GetEnvironmentString("MailServer", True)

    Set oDir = oSession.GetDbDirectory(strMailServer)
    Set oDBase = oDir.OpenMailDatabase

    If oDBase.IsOpen Then

    Set oDoc = oDBase.CreateDocument

    strImportance = "0"

    Call oDoc.ReplaceItemValue("Importance", strImportance)
    Call oDoc.ReplaceItemValue("Form", "Memo")

    'To: (for multi-recipient, use an array)
    Call oDoc.ReplaceItemValue("SendTo", astrTo)

    'Call oDoc.ReplaceItemValue("CopyTo", strCarbon)

    'Call oDoc.ReplaceItemValue("BlindCopyTo", strBCC)

    Call oDoc.ReplaceItemValue("DisplayReply", " ")
    Call oDoc.ReplaceItemValue("tmpDisplayReplyInfo", " ")

    ' *** Update here (Subject line of the e-mail)
    Call oDoc.ReplaceItemValue("Subject", strPOLICY)
    Set oRTStyle = oSession.CreateRichTextStyle
    Set oRTItem = oDoc.CreateRichTextItem("Body")
    oRTStyle.FontSize = 11
    oRTStyle.Underline = 0

    ' *** Update here (E-mail body updated by MAMONEC on July 8, 2008)

    oRTStyle.NotesColor = COLOR_BLACK
    Call oRTItem.AppendStyle(oRTStyle)
    oRTStyle.Bold = 0
    Call oRTItem.AppendStyle(oRTStyle)
    Call oRTItem.AppendText("Attached is the affirmation for " & strPOLICY & ".")
    'Call oRTItem.AddNewLine(2)
    'Call oRTItem.AppendText("")

    'Call oRTItem.AddNewLine(2)

    oRTStyle.Bold = 1
    oRTStyle.NotesColor = COLOR_BLACK
    Call oRTItem.AppendStyle(oRTStyle)

    ' Attach agent list in e-mail
    Call oRTItem.AddNewLine(2)
    Call oRTItem.EmbedObject(1454, "", strFile)
    UNID = oDoc.UniversalID
    oDoc.SaveMessageOnSend = True
    Call oDoc.Send(False) <----------------------Debugs here.
    If Err.Number = Trim("0") Then
    FullNotify = True
    FullNotify = False
    End If


    End If

    End Function

    The email still gets sent, but I need this error to go away. I captured the UNID on two separate runs, and they were different??? Help!

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    what do you do with UNID
    I can see you are assigning it the value from oDoc
    I would have expected you to assign a value to oDoc.UniversalID

    if all you want to od is make the message go away you could always turn warnings off OR trap for the specific error and decide what to do about it
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2012
    I'm actually not doing anything with UNID, I added that line of code in so I could test to see if the values were the same each time I ran the code. The Universal ID in Lotus Notes is a unique ID within the database, so to assign a value to it would not be possible.

    If I am creating duplicate Universal IDs, I dont want to replace others in error, in fear it might be causing problems with existing documents. So, I'm afraid I can't just trap this error and not repair.

    The odd thing is that this code works in another macro I use in Excel (which is where I got this code...) and I do not get an error, which makes me wonder if this is specific to Word. I made sure I had all of the same references. I googled this error several times and have had no luck :/

  4. #4
    Join Date
    Oct 2012


    For some reason, on occasion, when you create a new NotesDocument object, the UID that comes with the new document will be exactly the same as a previous one. I worked around it with this:

    In the message sending rotine I make the following call while preparing the document:

        newDocument.UNIVERSALID = GetLotusUID()
    and the function below generates a new UID:
    Public Function GetLotusUID() As String
        GetLotusUID = Replace(Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36), "-", "")
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts