Solved

Random 'Object Variable Not Set' on Notes

Posted on 2010-09-17
15
626 Views
Last Modified: 2013-12-18
I've created a database to track the projects in my workplace, but from time to time different users got 'Object Variable Not Set' error. The problem is it doesn't always happen. For example one user opened a project in process and got the error, when I debugged it, I see that one field somehow did not show up on the document hence causing the error when the code tried to get the value of the field. BUT when I tried to open the same project, it opened just fine.

Again, this doesn't happen everytime and the same user that got an error opening one project can open other projects just fine. But I know when the error message show up it's always caused by one field 'Status Comment'. What I don't understand is why it works sometimes and not the other times.

Attached is the snippet of the code
Set workspace = New NotesUIWorkspace
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document

...

Set item = doc.GetFirstItem("StatusComments")

' This is the point where the program stops. For some reason 'StatusComments field does not show up on the Item list in the doc
statuscomments1 = item.Text

Open in new window

0
Comment
Question by:coronoahcoro
  • 6
  • 6
  • 3
15 Comments
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 33702934
That just means that for some documents, there is no StatusComments item available.

Try using getItemValue which does not raise an exception for missing items.  Instead, if the item does not exist, an empty string is returned.
statuscomments1 = doc.getItemValue("StatusComments")(0)

Open in new window

0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 33702948
... Unless StatusComments is rich text.

For rich text, my idea won't work.  In this case, you need to check the 'item' variable before trying to access it.
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 33702963
Also, what event is this code behind?  You can't access new RichText in query save.  RichText is only available after the document is saved.

Sorry for the multi-post, but it's kind of hard to guess what context you are running under.  Posting the full code would help.
0
 
LVL 2

Author Comment

by:coronoahcoro
ID: 33704149
1. It is strange because when I open the document from my PC it opens just fine, but it gives the user the error. But if I go to edit mode and save the doc, then the user will not get the error anymore. I noticed that when the user get the error some other fields are missing and there is one item called 'NewForm' shows up on the debugger, which is strange because I never created that item.

2. It's just a text field with no default value.

3. The code is behind OnLoad form event. Basically I need to get the value of some fields when a user opens a document, then save the values in different variables so later after the user finishes editing the doc and save the doc, the code can compare the original value and the value on those fields after the save button is clicked. If the values are different then emails are sent depending on which fields are changed.

I attached the code on my OnLoad event.
Set workspace = New NotesUIWorkspace
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
	
If Not(uidoc.IsNewDoc) Then
	Set item = doc.GetFirstItem("Priority")
	priority1 = item.Text
	Set item = doc.GetFirstItem("Assignee")
	assignee1 = item.Text
	Set item = doc.GetFirstItem("Status")
	status1 = item.Text
	Set item = doc.GetFirstItem("IssueDescription")
	description1 = item.Text
	Set item = doc.GetFirstItem("StatusComments")
	statuscomments1 = item.Text
	Set item = doc.GetFirstItem("Updates")
	statusupdater1 = item.Text
End If

Open in new window

0
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 125 total points
ID: 33704927
The only thing I see wrong is the way you are accessing the current document.

Never use NotesUIWorkspace.CurrentDocument in form events!  The event methods provide you with an in-memory copy of the current ui document which is more reliable.

Here's the preferred method for reading values in OnLoad...
Sub Onload(Source As Notesuidocument)

	If Not(source.IsNewDoc) Then

		Set doc = source.Document

		priority1 = doc.GetItemValue("Priority")(0)

		assignee1 = doc.GetItemValue("Assignee")(0)

		status1 = doc.GetItemValue("Status")(0)

		description1 = doc.GetItemValue("IssueDescription")(0)

		statuscomments1 = doc.GetItemValue("StatusComments")(0)

		statusupdater1 = doc.GetItemValue("Updates")(0)

	End If

End Sub

Open in new window

0
 
LVL 10

Expert Comment

by:doninja
ID: 33707890
if using back end document from uidoc whtn I always do a check for field existence before trying to access any value. you can then atleast give the user mare valid return message rather than an error

Or more importantly you can set the item to a default value, bypass or try reloading the back end document incase it was due to a timeout processing the doc etc.

You can also try testing the type to ensure it is a text item





if item is nothing then
  messagebox("Error with StatusComment field", 0 , "Error")
elseif item.type <> 1280 then
  'item not text
end if

Open in new window

0
 
LVL 10

Expert Comment

by:doninja
ID: 33707894
As other things to look at, does the form use an subforms or any areas that have lookups to other databases. Maybe the access the user has to perform some of the lookups does not fill in all the fields. bt when you run it your permissions save all of the relevant lookup data into the document for the next person to view ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:coronoahcoro
ID: 33713696
Thanks Bill-Hanson for the suggestion. I am just following what the Help file says :) I'll try your code tomorrow.

doninja, checking the field existence is a good idea but if the user gets an error, what's next? sending more meaningful error message won't fix the problem. Like I mentioned before, it occurs randomly, there is no pattern whatsoever. I want to know is it a mistake on my code or Notes just behaving strangely. if it is a mistake on my part then there has to be a way to fix it, but it is one of Notes quirkiness then I'm so ready just to leave it alone.

No the form doesn't use a subform, and there is only one field that uses lookup and it isn't the comment field.
0
 
LVL 10

Expert Comment

by:doninja
ID: 33714298
can't give you exact reason why this happens as a lot of variables.
Maybe instead of error message you could first try reloading the backend doc.
clear the Doc variable and reoad from uidoc.document

It is a work around rather than solution but if it works then it could point to some client issue with instal of notes, connectivity etc
0
 
LVL 2

Author Comment

by:coronoahcoro
ID: 33727436
Bill, I'm reading your last comment again. 'Never use NotesUIWorkspace.CurrentDocument in form events! '. I'm curious, in what situation is NotesUIWorkspace.CurrentDocument used? Like I said most of the examples from Notes Help use NotesUIWorkspace.CurrentDocument to reference to the document that is currently opened.
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 33728211
You would use it everywhere except in a form event that already provides the necessary handle: behind an action button, a hotspot link, in an agent, in a script library, in a  field's onChange event, etc...

Notes documentation has never been known for completeness, but I've been doing this for a very long time.  Have you even tried my code yet?
0
 
LVL 2

Author Comment

by:coronoahcoro
ID: 33799519
Yes I've changed my code on the onChange field according to your code and it behaves normally. I'm in the process of rewriting my action button using your method.
0
 
LVL 2

Author Comment

by:coronoahcoro
ID: 33800505
Now if I have an action button, can I use the code below to access current doc?




Sub Click(Source As Button)
  Set workspace = New NotesUIWorkspace
  Set uidoc = workspace.CurrentDocument	
  Set doc = uidoc.Document

...

  Set item = doc.GetFirstItem("ReportedBy_Email")
...
End Sub

Open in new window

0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 33800972
Yes.

The difference is in the form timing.  Behind a button, workspace.CurrentDocument correctly represents the current document, but in the form events (onLoad, queryOpen, postOpen, queryModeChange, etc...), it may or may not depending on the context and timing.  That's why they give you a direct handle in all form events.
0
 
LVL 2

Author Closing Comment

by:coronoahcoro
ID: 33841964
It seems that no one is having the problem after I changed the code to what Bill-Hanson suggested. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now