Creating memo using Lotusscript

I am having a brain cramp trying to create a button on a form that will create a memo in the current user’s mail database and populate the new memo with fields from the current form.

My current code will create the memo and populate the mail address fields and subject but I’ve hit a sticky spot trying to copy the rich text field on the application form into the new memo. My script works fine if I remark out the CopyItemToDocument line. Otherwise I get the “Object variable not set” message. I suspect this is not a challenging programming question for someone who really knows Lotusscipt but that’s not me! Thanks for your help. Here’s my code.

Sub Click(Source As Button)

Dim session As New notessession

Dim ws As New notesuiworkspace

Dim uidoc As notesuidocument

Dim db As notesdatabase

Dim doc As notesdocument

Dim mail As notesdatabase

Dim memo As notesdocument

Dim body As notesrichtextitem	



Set db=session.currentdatabase

Set uidoc=ws.currentdocument

Set doc=uidoc.document	

Set mail = New notesdatabase("","")



Call mail.openmail

Set memo = mail.createdocument

memo.sendto=doc.mailaddress

memo.subject=doc.subject

Set body= doc.GetFirstItem("Body")

Call body.CopyItemToDocument(memo,"Body")



Call ws.editdocument(True,memo,False)

End Sub

Subject: Creating memo using Lotusscript

Did you see the example in HELP:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim memo As NotesDocument

Dim itemA As NotesItem

Dim itemB As NotesItem

Set db = session.CurrentDatabase

'…set value of doc…

Set itemA = doc.GetFirstItem( “Body” )

Set itemB = doc.GetFirstItem( “BriefDescription” )

Set memo = New NotesDocument( db )

Call itemA.CopyItemToDocument( memo, “Body” )

Call itemB.CopyItemToDocument( memo, “Subject” )

Call memo.Send( False, “Cynthia Brainey” )

Try using a notesitem to get the value of the body field.

Subject: RE: Creating memo using Lotusscript

Thanks for your posting. I used the help that you referenced as my starting point. I have tried it with both notesitem and notesrichtextitem but still get the same error message. This is a segment from my previously posted script where I believe I have matched the help example code.

Dim body As notesrichtextitem

Set body= doc.GetFirstItem(“Body”)

Call body.CopyItemToDocument(memo,“Body”)

Subject: RE: Creating memo using Lotusscript

Are you sure your original form has a field called “Body”? Use the lotusscript debugger and check that you rich text item called Body does actually get set. The item on the memo form is called Body, but is the one on the first form?

Dan

Subject: RE: Creating memo using Lotusscript

There is a body field on both forms. I just found out that if I save the form first before clicking the button to create the new memo it works. However, when I try to do the save in the script using Call doc.Save(False,False) it doesn’t. Again, I’m not a 'scripter so I may be missing something really basic. Here’s what I have now where I’m just trying to save the original document programmatically in the script before the new memo document is created. Thanks for the help:

Sub Click(Source As Button)

Dim session As New notessession

Dim ws As New notesuiworkspace

Dim uidoc As notesuidocument

Dim db As notesdatabase

Dim doc As notesdocument

Dim mail As notesdatabase

Dim memo As notesdocument

Dim itemA As notesitem	



Set db=session.currentdatabase

Set uidoc=ws.currentdocument

Set doc=uidoc.document	

Set mail = New notesdatabase("","")



Call mail.openmail

Set memo = mail.createdocument

memo.sendto=doc.mailaddress

memo.subject=doc.subject

Call doc.Save(False,False)

Set itemA= doc.GetFirstItem("Body")

Call itemA.CopyItemToDocument(memo,"Body")





Call ws.editdocument(True,memo,False)

End Sub

Subject: RE: Creating memo using Lotusscript

Save using uidoc.save. After the line set uidoc = ws.currentdocument put:

If uidoc.isnewdoc and uidoc.editmode = true then

call uidoc.save

End If

set doc = uidoc.document

etc.

Subject: Ah ha.

Just what I needed. It’s working perfectly.

Thanks VERY much,

Mike