This script gives me an error message of “object variable not set” when executed. Can anyone help to resolve?
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim itemA As NotesRichTextItem
Set db = session.CurrentDatabase
Set doc = workspace.CurrentDocument.Document
Set itemA = doc.GetFirstItem ("ChgDetails")
Call itemA.CopyItemToDocument(doc, "ChgDetails_RO")
Thanks in advance,
Linda
Subject: Object variable not set
Linda,
Most likely the field name is not a valid field. You can use doc.hasitem or check for (item is Nothing) to make your code a bit more robust.
However, just drop into Lotuscript debug mode and run the script again. It will bomb on the line that’s not working and you’ll be able to see all the variables and what they instantiated to.
Subject: RE: Object variable not set
Hi Matt,
Thank you for your suggestion to run the debugger. The failure occurs on this line:
Call itemA.CopyItemToDocument(doc,“ChgDetails_RO”)
The field name is a valid field name, but it’s position is positioned physically below the source field ie ChgDetails on the form.
I still do not understand why this occuring??
Any other ideas?
Subject: RE: Object variable not set
Object variable not set always means that something you are trying to use is not instantiated. In this case, you are focusing on the method of the NotesItem, but I don’t think that’s the problem.
Either the doc or itemA are not instantiated when you attempt to call the CopyItemToDocument method. In debugger, look at the variables. I bet either doc or itemA are not set to anything.
You could also add this to your code:
if doc is nothing then messagebox “no doc”
if itemA is nothing then messagebox “no item”
In what context is this code running? Button click? QueryOpen?
Subject: RE: Object variable not set
Hi again,
The code is attached to the exiting event of “ChgDetils”.
I entered your code and received the message “no item”.
When running the debugger and then reviewing it’s contents, I do not see the field “ChgDetails” specified anywhere within the variables tab … I find this confusing???
Subject: RE: Object variable not set
You wrote:‘Hi again, The code is attached to the exiting event of “ChgDetils”.’…
Is it possible you typoed in your code or in the field name itself same as you did in that quote?
Subject: RE: Object variable not set
Can you post the current verion of the script here?
Subject: RE: Object variable not set
Here is the current version of the script: Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim itemA As NotesRichTextItem
'…set value of doc…
Set db = session.CurrentDatabase
Set doc = workspace.CurrentDocument.Document
If doc Is Nothing Then Messagebox "no doc"
Set itemA = doc.GetFirstItem ( "ChgDetails" )
If itemA Is Nothing Then Messagebox "no item"
Call itemA.CopyItemToDocument(doc,"ChgDetails_RO")
Subject: RE: Object variable not set
Hi Mikels
here is the corrected code . HTH
regards
ramesh
==== corrected code
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
dim uidoc as NotesUIDocument
Dim doc As NotesDocument
Dim itemA As NotesRichTextItem
'…set value of doc…
Set db = session.CurrentDatabase
set uidoc = workspace.Currentdocument
set doc = uidoc.Document
'Set doc = workspace.CurrentDocument.Document
If doc Is Nothing Then Messagebox “no doc”
Set itemA = doc.GetFirstItem ( “ChgDetails” )
If itemA Is Nothing Then Messagebox “no item”
Call itemA.CopyItemToDocument(doc,“ChgDetails_RO”)
Subject: RE: Object variable not set
You’re actually attacking the wrong issue. There is no need to add a uidoc declaration. While her use of workspace.Currentdocument.Document might go against your personal style preferences, it’s totally functional. Your code has the same bug hers does, namely a type mismatch on assignment of a NotesItem to a NotesRichTextItem object. 
Subject: RE: Object variable not set
You must have an “on error resume next” statement in there for you to be getting to the “no item” error without first getting a type mismatch on your assignment of a NotesItem to a NotesRichTextItem object. Just change the last variable declaration to:
Dim itemA As NotesItem
That code will run as expected with this one change.