Variant does not contain an object

Hi, please help me find the error on my script below…

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim tmpSeqNo As Variant

Dim NxtSeqNo As Variant

If source.IsNewDoc=True Then

tmpSeqNo = doc.GetItemValue(“SequenceNo”)

If Isnumeric(tmpSeqNo(0)) = True Then

NxtSeqNo = tmpSeqNo(0) + 1

Else

NxtSeqNo = 1

End If

NxtSeqNo = Cstr(NxtSeqNo)

Call Source.FieldSetText (“SequenceNo”, NxtSeqNo)

End If

Subject: Variant does not contain an object

You can use the debugger to tell what line the error is on - select File > Tools > Debug Lotusscript on your Notes client to turn it on.

Subject: Variant does not contain an object

First thing you did not declare “doc”.

Hence add these lines:

dim doc as Document

set doc = Source.Document

Then use the GetItemValue thing and proceed. No need to convert cstr(NxtSeqNo) and assign it to variant again because NxtSeqNo is itself a variant.

Why do you want to get the content into variants.

simply do this:


Dim tmpSeqNo As integer

Dim NxtSeqNo As integer

If source.IsNewDoc Then

 tmpSeqNo = Cint(Source.FieldGetText 

             ("SequenceNo"))

 if tmpSeqNo > 0 then

      NxtSeqNo = tmpSeqNo + 1

 Else 

      NxtSeqNo = 1

 End If



 Call Source.FieldSetText ("SequenceNo", 

 cstr(NxtSeqNo))

End If


You can also simplify your code by removing “= True” because, for eg.

“If source.IsNewDoc=True Then” is same as:

“If source.IsNewDoc” Then

Also FYI,

If you want to check false, you can write the code as: “If Not source.IsNewDoc Then”

Subject: RE: Variant does not contain an object

Hi Narasimhan,

thanks a lot. i haven’t encountered any error. However counter is not working…my default value for SequenceNo is zero.

seems the value of SequenceNo is not incrementing when New Doc is clicked.

what seems to be the problem?

i wanted to increment the SequenceNo if IsNewDoc…please help

:slight_smile:

Subject: RE: Variant does not contain an object

Hi,

you should put

Option Declare

into the Options section of your code. This will help you to get rid of some errors already at compile-time. To find runtime-errors you should include an error-handler which not just tells you what happened, but also where it happened:

Sub Querysave(Source As Notesuidocument, Continue As Variant)

On Error Goto processError

Dim tmpSeqNo As Variant

Dim NxtSeqNo As Variant

If source.IsNewDoc=True Then

tmpSeqNo = doc.GetItemValue(“SequenceNo”)

If Isnumeric(tmpSeqNo(0)) = True Then

NxtSeqNo = tmpSeqNo(0) + 1

Else

NxtSeqNo = 1

End If

NxtSeqNo = Cstr(NxtSeqNo)

Call Source.FieldSetText (“SequenceNo”, NxtSeqNo)

End If

Exit Sub

processError:

Msgbox("Error " & CStr(Err) & " in line " & CStr(Erl) & ": " & Error$)

Exit Sub

End Sub

Best regards
Mario Varchmin

Subject: RE: Variant does not contain an object

thanks…

i forgot to add below in my script…its working now:

Set collection = db.AllDocuments

Set doc = collection.GetLastDocument

thanks anyway…

Subject: Variant does not contain an object

At a glance, it looks like you just need to dim and set the “doc” variable.

dim doc as NotesDocument

set doc = Source.Document

Two other suggestions:

Use “Option Declare” or “Option Explicit” – this forces you to declare all variables and helps avoid problems like this

Use the debugger

Use some error trapping. For example:

On error goto errorHandler

'{variable declarations}

'{set variables}

'{process data}

thisExit:

Exit sub '// or exit function

errorHandler:

msgbox "Error " & err & ": " & Error$ & " encountered at line " & erl & " of " & getthreadinfo(1) & “.”, , “Error . . .”

print "Error " & err & “: " & Error$ & " encountered at line " & erl & " of " & getthreadinfo(1) & " . . .”

resume thisExit

hth,

dgg