Search code examples
lotus-noteslotusscriptlotus

Set a date field with AdjustDay (NotesDateTime Class)


I have a problem with my code, at the end when the script tries to save de doc lotus show me an error:

Validation error on format.

I want to change the day reminder and I am trying first in a event buttom and then I would like to implement this code into an agent, is this...

Sub Click(Source As Button)

'... other variables declared ...

Dim dateTime As NotesDateTime
Dim nuevoRecordatorio As Variant

Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Set item = doc.GetFirstItem("TempoFechaRecordatorio01")
Set dateTime = item.DateTimeValue

Messagebox (dateTime.DateOnly)

Call dateTime.AdjustDay(15)

Messagebox (dateTime.DateOnly)

nuevoRecordatorio = dateTime.DateOnly

Messagebox (nuevoRecordatorio)

Set item2 = doc.ReplaceItemValue("TempoFechaRecordatorio01",Cdat(nuevoRecordatorio))

Messagebox (doc.TempoFechaRecordatorio01(0))

Call uidoc.Save
Call uidoc.Close End Sub

I have tried without Cdat(...), but the result is the same: format error.

Could anyone give me any instruccion to fix this problem?


Solution

  • NotesDateTime.DateOnly property returns a string value, so you need to convert this value to date value by using DateValue function:

    'Your code.
    
    Set item2 = doc.ReplaceItemValue("TempoFechaRecordatorio01", DateValue(nuevoRecordatorio))
    
    'Your code.
    

    Also you can use date values directly:

    'Your code.
    vDate = doc.GetItemValue("TempoFechaRecordatorio01")(0)
    
    vDate = vDate + 15
    
    doc.ReplaceItemValue("TempoFechaRecordatorio01", Datenumber(Year(vDate), Month(vDate), Day(vDate))
    'Your code.
    

    In other way you can use Evaluate function:

    'Your code.
    
    doc.ReplaceItemValue("TempoFechaRecordatorio01", Evaluate({@Adjust(@Date(TempoFechaRecordatorio01); 0; 0; 15; 0; 0; 0)}, doc)
    
    'Your code.