EmbedObject not recognizing file already created

I have run into a strange problem that seems to only occur for some people a handful of times and haven’t been able to pinpoint the cause. We have an agent that when triggered by a form action it creates a Word document, saves it to c:\temp, and then attaches that newly created Word document to a rich text field (called Attachment). Suddenly, I have 3 users that get an error message that says ‘Invalid or Non-Existent document’ when this code is running. It appears as if the file is not being recognized. When debugging the code, the line that it errors out on is ‘Set object=rtitem.EmbedObject(EMBED_ATTACHMENT,“”, currentFileName & “.dot”)’. If I reference an Err number, I get error 4067. I am unable to reproduce the problem on my pc which has the exact same version of Notes and Windows.

Can anyone tell me why this would only happen to a few people and how I can fix it? Any help would be greatly appreciated!

Sub Initialize

Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments



'Template Processing

If Template_Process() = False Then

	Exit Sub

End If



'Create the Word object:

Set WordApp = CreateObject("Word.Application")

WordApp.documents.open(filename)



Set doc = dc.GetFirstDocument()

If doc Is Nothing Then Exit Sub



Call GetFieldList



If dc.Count = 1 Then

	'Populate the Word Template

	For i = 0 To Ubound(fieldList)

		WordApp.ActiveDocument.Bookmarks(fieldName(i)).Select 

		WordApp.Selection.TypeText(fieldList(i))

	Next

	

	poNum = doc.PONum(0)

	poNum = Left(poNum, 4) & Mid(poNum,6)

	currentFileName = tmpdir & "\" & poNum

	

	WordApp.ActiveDocument.saveas (currentFileName)

	WordApp.ActiveDocument.close

	WordApp.Quit 

	

	'Add attachment to document

	Dim rtitem As notesrichtextitem

	Dim object As notesEmbeddedObject

	Set rtitem=New NotesRichTextItem (doc,"Attachment")

	Set object=rtitem.EmbedObject(EMBED_ATTACHMENT,"", currentFileName & ".dot")

	

	'Set DocAuthors field

	Dim author(2) As String 

	author(0) = "[Designer]"

	author(1) = "[Maintenance]"

	author(2) = "[Receiver]"

	doc.DocAuthors = author

	

	

	Call doc.Save(True, False)

End If



If doc.EmailPO(0) = "Yes" Then

	Call SendEmail

End If

End Sub

Subject: EmbedObject not recognizing file already created

I haven’t had the need to do any COM processing of office douments. Having said that, have you checked to see if the C:\temp directory exists on the user’s PC? Have you checked that the user actually have access to C:\temp? Is a document created at C:\temp? Is Word actually creating a document?

/Peter

Subject: RE: EmbedObject not recognizing file already created

Yes, the directory does exist on the user’s PC and they do have access to the directory (no restrictions). A document is created and put in the correct directory therefore I don’t see this being a permissions problem otherwise I would suspect the Word document would never be created. Any suggestions?

Subject: EmbedObject not recognizing file already created

Hi Veronika,Have you tried running filemon from sysinternals.com? - http://www.sysinternals.com/Utilities/Filemon.html

This would tell you if the correct file name is being queried for, as well as if the file is in use (antivirus?) or access is denied.

Are the verions of MS Word the same as well?

Hope that helps,

Bruce

Go Huskies! :slight_smile: