How can assignment to Variant be Type Mismatch?

A LotusScript agent runs during WebQuerySave() .It has a variable in the Declarations section

Dim DocDate as Variant

(Options does have Option Public)

In a subroutine the following code throws an Error 13 Type Mismatch :

Dim DateItem As NotesItem

If dbDateField=“None” Or ( Not docResult.HasItem(dbDateField) )Then

Set docDate=docResult.Created

Else

Set DateItem=docResult.GetFirstItem(dbDateField)

Set docDate = DateItem.Values(0) '<------ mismatch on this line

’ Also tried with same result: Set docDate=docResult.GetItemValue(dbDateField)(0)

End If

The code already tested that DocResult is not Nothing, and it was set with

Dim docResult As NotesDocument

Set docResult = viewSearch.GetFirstDocument

The value of dbDateField happens to be “UpdateDate”. All the documents have an item by that name, and the item’s datatype is Time/Date on all the ones I looked at.

This code is copied straight from a working app! What’s wrong here?

Subject: How can assignment to Variant be Type Mismatch?

What’s puzzling me isn’t that you’re getting an error so much as that you’re getting that error. docDate isn’t an object, so you shouldn’t need the Set statements. What happens if you just use docDate = DateItem.Values(0)?

Subject: How can assignment to Variant be Type Mismatch?

It’s because you’re trying to access the notesitem incorrectly eg values(0) you need to do it like this docDate = DateItem.values

See if that works

Subject: How can assignment to Variant be Type Mismatch?

Get rid of the variant; use a notesdatetime instead.

Subject: is dateitem nothing?

Hi!

Is it possible, that the object of dateitem is nothing?

michael

Subject: How can assignment to Variant be Type Mismatch?

Hi,

it is either the “Set” or the “(0)”. You are not assigning an object in that line, so you should not use “Set”. If it still doesn’t work, use the TypeName function to find out the data type of DateItem.Values:

Set DateItem=docResult.GetFirstItem(dbDateField)

Msgbox(TypeName(DateItem.Values))

Set docDate = DateItem.Values(0) '<------ mismatch on this line

Best regards
Mario Varchmin

Subject: Thanx! for All the Replys

Thank you for your help.

It turns out that the improper use of “Set” was provoking the error. One of those cases where you stare at it so long that you can’t see it.