Link to home
Start Free TrialLog in
Avatar of Hartini_Othman
Hartini_Othman

asked on

Lotus notes Error 4005 : invalid or nonexistent document when try to extract an attachment

I have a scheduled agent that detach an Excel file attachment from a document into a  temp folder in the server.
I got this error message when the agent tries to extract the attachment file from the rich text field in the document:
'Error 4005 : notes error : Invalid or nonexistent document'
The attachment is there. Is it because of the document is invalid or it cannot find the attachment?
Anybody has any idea on how to solve this problem? Please help
Avatar of SysExpert
SysExpert
Flag of Israel image

Please post your code so that we can see what the issue may be.

Also , did you try this on a local workstation - client ?


I hope this helps !

Avatar of Hartini_Othman
Hartini_Othman

ASKER

I've try in the local workstation and also run the agent manually, it works. The agent runs in the German Server of our customer site, I try to reproduce the error by testing it in my company server, but still I cannot get the error message.
Here is the code:

Public Sub DetachExcelToTempFolder (oDoc As notesdocument, sExcelFileAndPath As String)
      
      On Error Goto errh      
      Dim strFileName As String, sTempPath As String, nTempSize As Long
      Dim oItem As NotesRichTextItem, oEmbObj As NotesEmbeddedObject
      
      Set oItem = oDoc.GetFirstItem("imstc_OriFile") '<--- the attachment is stored in this  field      
      
      Forall vChild In oItem.EmbeddedObjects                  
         If ( vChild.Type = EMBED_ATTACHMENT) Then
               strFileName = vChild.source
              Exit Forall
         End If
      End Forall
            
      '--- Define Path to store the Excel file temporarly
      sTempPath = Space$(256)
      nTempSize = Len(sTempPath)
      Call GetTempPath(nTempSize, sTempPath)
      sTempPath = TrimNull(sTempPath)
      sExcelFileAndPath = sTempPath & strFileName
      
      
      If Dir(sExcelFileAndPath) <> "" Then Kill sExcelFileAndPath      
      '--- Detach the file
      Set oEmbObj = oItem.GetEmbeddedObject(strFileName)
      oEmbObj.ExtractFile sExcelFileAndPath     '< ---- the error occured in here
      

      
End Sub

ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Sjef, I'll look into that
Glad it's solved, but what wasn't correct (except for spelling errors)? You gave a B...