Object variable not set - Notesdatetime

Hi,

I am trying to get difference between 2 dates. But when I pass value from the document to a variable is says object variable not set.

Dim date1 as notesdatetime

set date1=New Notesdatetime(doc.datefield(0)) → Here I get error

While debuggin I found that datefield is blank. To my understanding if blank then value for date1 also becomes blank (“”).

Out of 10 documents 6 are blank and for few it does not throw error but for few it gives error.

Any ideas why it is acting wierd.

Subject: Object variable not set - Notesdatetime

If you send a value to the New method of the NotesDateTime, it has to be a string that can be interpreted as a date/time (or a value that can be implicitly converted to a legal date-time string). An empty string cannot be interpreted as a date/time value.

Subject: RE: Object variable not set - Notesdatetime

I don’t know whether you bothered to search, but this message is documented in the Domino Designer help and there are also over 1000 posts about it in this forum.

Debugging Domino Applications part 1 and part 2 contains an exact description of this error, with an example, and also many tips for tracking down errors yourself, instead of trying to win the prize for asking the most-asked question.

Subject: Object variable not set - Notesdatetime

hi,

doc.datefield(0) returns “” if the field is within the document.

try

dim oitem as notesitem

set oitem=doc.getfirstitem(“datefield”)

set date1=oitem.Values(0)

you may now using the debugger to see if the item is set in for each document.

by the way…passing a blank value to the constructor of notesdatetime results in a wildcard date.

Parameters

dateTime$

String. The date and time you want the object to represent. If you use an empty string (“”), the date is set to a wildcard date. The Notes date-time expressions “Today,” “Tomorrow,” and “Yesterday” are supported.

Hth

Alex