'How do I get the year from a date in VBA?

I have a VBA user form where there is a text-box(txt_Date) to input the date. I want to get the year from this date. I have tried,

sh.Range("G" & lr + 1).Value = Format(txt_Date.Text, "yyyy")

and

sh.Range("G" & lr + 1).Value = Year(txt_Date.Value)

For the date, 4-May-2022, I get the output 14-Jul-1905 in both the above cases. How do I get the correct year, 2022, in this case?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source