If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back  dBforums > PC based Database Applications > Other PC Databases > Word Macro VBA Lotus Domino Error - Notes Error: Database Already Contains a Document

LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Registered User
Join Date: Apr 2012
Location: Pennsylvania
Posts: 2
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!
Reply With Quote
  #2 (permalink)  
Jaded Developer
Join Date: Nov 2004
Location: out on a limb
Posts: 12,307
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
Is taking part in the 'Distinguished Gentlemans' ride. Being neither distinguished nor a gentleman, but I am keen to raise funds for Prostrate Cancer research. At present I'm threatening to ride a Norton 961 wearing a kilt. If you would like to contribute to Prostrate Cancer research then please consider donating via this page:-
Reply With Quote
  #3 (permalink)  
Registered User
Join Date: Apr 2012
Location: Pennsylvania
Posts: 2
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 :/
Reply With Quote
  #4 (permalink)  
Registered User
Join Date: Oct 2012
Posts: 1

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
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On