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)
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.
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?
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)