Question : LotusScript Embed_Attachment Type Mismatch

I have the following code in an action button & I get a type mismatch on the Set ObjAttachment line.
Any ideas that anyone has would be greatly appreciated...

Sub Click(Source As Button)
      Dim ws As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim RTDocField As Variant
      Dim ObjAttachment As NotesEmbeddedObject      
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Set db = session.currentdatabase
      Set uidoc = ws.CurrentDocument
      
      If uidoc.Editmode = False Then
            Set uidoc = ws.EditDocument( True )
      End If
      CurrentServer$ = db.Server
      CurrentFile$ = db.FileName
      
      CheckAssign = ws.Prompt(PROMPT_YESNO, _
      "Please Read!", "Do you wish to complete this request?" & _
      " If so, click YES otherwise, click NO to cancel."  , "", "")      
      
      If uidoc.FieldGetText("AssignedTo") = " Un-Assigned" Then
            Messagebox "Request not assigned!  Requests must be assigned to a Metrics & Analytics representative prior to completion.",  MB_OK + MB_ICONEXCLAMATION, "ERROR"
            Exit Sub
      End If
      
      
      If CheckAssign = 1 Then
            
            Dim CurrentUser As New NotesName(session.UserName)
            
            Dim Rep As New NotesName(uidoc.document.Approver(0))
            
            CheckAttach = ws.Prompt(PROMPT_YESNO, _
            "Attachments", "Would you like to attach a file to this request?" & _
            " If so, click YES otherwise, click NO to cancel."  , "", "")      
            
SelectFile:
            If CheckAttach = 1 Then
                  FileNameString = ws.OpenFileDialog( True, "Select files to attach...", , , )
                  Set doc = uidoc.Document
                  Set RTDocField = doc.GetFirstItem("ResolutionAttachments")
                  
                  If (RTDocField.Type = RICHTEXT) Then
                        Set ObjAttachment = RTDocField.EmbedObject(EMBED_ATTACHMENT, "",FileNameString )
                  End If
            End If
            
      End If
      
End Sub

Answer : LotusScript Embed_Attachment Type Mismatch

Good point tiler, but since CEB0827 is closing the document immediately after attaching, he can avoid that problem.

You can try to do a back-end save after attaching, instead of the front end:
    Call doc.Save( True, False, True )

instead of
    Call uidoc.Save

And to save all changes user has made to document before clicking your attach button, you can call uidoc.save at the top of your code.

And change this part of your code:

If uidoc.Editmode = False Then
 Set uidoc = ws.EditDocument( True )
End If

like this:

If uidoc.Editmode = False Then
 uidoc.Editmode = True
End If

The workspace method, without NotesDocument argument, is intended to be used in views to open currently selected document.
Random Solutions  
 
programming4us programming4us