Date item, multiple values of NotesDateRange and NotesDateTime

I have two date fields on a form (startdate and enddate). Now I’m trying to populate a third date field with multiple values from that fields. The new entry can be a daterange or a single value (if startdate and enddate are the same). My problem is the syntax to get the new value into the existing array.

Dim ws As New NotesUIWorkspace

Dim session As New NotesSession

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim dtStart As NotesDateTime

Dim dtEnd As NotesDateTime

Dim item As NotesItem

Dim values As Variant

Dim dateRange As NotesDateRange

Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document

Set dtStart = New NotesDateTime(doc.getitemvalue(“StartDate”)(0))

If (doc.getitemvalue(“EndDate”)(0)<>“”) Then

Set dtEnd = New NotesDateTime(doc.getitemvalue(“EndDate”)(0))

Else

Set dtEnd = dtStart

End If

Set dateRange = session.CreateDateRange()

Set dateRange.StartDateTime = dtStart

Set dateRange.EndDateTime = dtEnd

Set item = doc.GetFirstItem(“Ferien_Daten”)

If Not item Is Nothing Then

values = item.GetValueDateTimeArray()

End If

Dim ub As Integer

ub = Ubound(values)

Redim Preserve values(ub+1)

Set values(ub+1) = dateRange

doc.Ferien_Daten = values

Call uidoc.Refresh

So I use the new “GetValueDateTimeArray”. The problem is if there’s even one “single value” thats no daterange, the type of the values-array is notesdatetime and I get a type mismatch error with “Set values(ub+1) = dateRange”. If there are only dateranges in the field the type of values is notesdaterange and it works. If I save the date field it shrinks a daterange with a single value to a datetime. So I get the error next time I try to populate the field. Has anybody an idea about that?

Subject: Date item, multiple values of NotesDateRange and NotesDateTime

Try…

dim fDate as variant ’ may contain dateTime or dateRange

If dtStart.lsLocalTime = dtEnd.lsLocalTime then ’ start and end time are identical

set fDate = dtStart

else

Set dateRange = session.CreateDateRange()

Set dateRange.StartDateTime = dtStart

Set dateRange.EndDateTime = dtEnd

set fDate = dateRange

end if

call doc.replaceItemValue(“Ferien_Daten”, fDate)

Call uidoc.Refresh