Dim s As New notessession Dim db As notesdatabase Dim docT As notesdocument Dim uiw As New notesuiworkspace Dim uidoc As notesuidocument Dim tcategory As String Dim tattach As NotesItem Set db = s.currentdatabase Set uidoc = uiw.currentdocument Call uidoc.refresh tcategory = uidoc.fieldgettext ("tcategory") Set tattach = docT.GetFirstItem ( "tattach" ) Set docT = db.createdocument With docT .form = "todo" .category = tcategory Call docT.CopyItem( tattach, "attach" ) End With
CopyItem is a LotusScript method for copying an item of the type NotesItem. A NotesItem is only available on a background document.
Call docT.CopyItem( tattach, "attach" ) is OK except for the bit where it says
tattach. Tattach is not a reference to a NotesItem, it is a field on the foreground document -- the UIdoc.
What you need to do is something like this:
Call uidoc.Save Dim backDoc As Notesdocument Set backDoc = uidoc.Document Dim tattachItem As NotesItem Set tattachItem = backDoc. GetFirstItem("tattach") Call docT.CopyItem(tattachItem, "attach" )I believe that this would do the trick.
Do you have comments on this Ask the Expert Q&A? Let us know.