How do I pass attachments from one form to another using LS?

How do I pass attachments from one form to another using LotusScript? I have script (see below), which works well for all number, date and text fields, but will not work for Rich Text. Basically I have a data input form on a page on the frameset, which is used to create documents in the background. Below is a shorten script that generates "Object Variable Not Set" on line "Call docT.CopyItem( tattach, 'attach' )".
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
Set tattach = docT.GetFirstItem
( "tattach" )
Set docT = db.createdocument
With docT
.form = "todo"
.category = tcategory
Call docT.CopyItem( tattach, "attach" )
End With
Your problem lies in you mixing background and foreground methods.

CopyItem is a LotusScript method for copying an item of the type NotesItem. A NotesItem is only available on a background document.

So your 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.
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.

Dig Deeper on LotusScript



  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...