Your variable "datevar" is an object of class "NotesDateTime". Objects are no primitives and cannot be converted to a string easily.
In addition "DateOnly" is a property of that class NotesDateTime and
doc.GetItemValue( "Datum" )(0)
which is a long form for
doc.Datum(0)
does not return a NotesDateTime but a variant of type Date/Time what is a big difference.
That means: After that line the variable datevar is not even initialized but "Nothing". And that is the reason for the type mismatch.
You need to do the following:
- create the object from the document value
- get the DateOnly
- no need to convert to a string as DateOnly already returns a string
The resulting code:
Set datevar = New NotesDateTime( doc.Datum(0) )
datevarstr = dateVar.DateOnly
path_var = datevarstr
Now to the big downside of this:
You can never be sure that the format of your string is correct.
As you use the German item name "Datum" I assume that you might have stumbled over the different date formats (dd.mm.yyyy vs. mm/dd/yyyy vs. yyyy-mm-dd).
If your code runs on a server with English locale / date settings then the result for today in "path_var" will be 01/25/2023. If you run it on your client with German locale it will most probably be 25.01.2023, if you change your os setting to English you will again get the English format: not very good and predictable option for directories...
Better use the "Format" option to directly format your date however you need it to be: easier, less code and more consistent:
'- ISO date, best for sorting directories
datevarString = Format( doc.Datum(0), "yyyy-mm-dd" )
'- German
datevarString = Format( doc.Datum(0), "dd.mm.yyyy" )
'- English
datevarString = Format( doc.Datum(0), "mm/dd/yyyy" )