In a form, I want to put make a default date. I want it to be January 1st of the current year. Any ideas?
In a form, I want to put make a default date. I want it to be January 1st of the current year. Any ideas?
Cdate("01/01" & year(now))
Didn't work. Access changed it to: CDate("01/01" & Year(Now()))
But, that gave me an error also.
Try
Cdate("01/01/" & year(Date))
if you observe what you have typed, you will see entering
Cdate("01/01/" & year(Date))
access automatically changes it to
Cdate("01/01/" & year("Date"))
This is because date is a function so needs the () at the end. Try
Cdate("01/01/" & year(Date()))
Immediate window
?Cdate("01/01/" & year(Date))
01-Jan-2017
?Cdate("01/01/" & year(Date()))
01-Jan-2017
?date
17-Jun-2017
?date()
17-Jun-2017
In a sub:
Access /vba will remove the () and convert
year(Date())) to year(Date))
but still renders correct date.
Result:Code:Sub testdat() Debug.Print CDate("01/01/" & year(Date)) Debug.Print CDate("01/01/" & year(Date)) '<---- () removed when I move off the line (syntax check) Debug.Print Date Debug.Print Date End Sub
01-Jan-2017
01-Jan-2017
17-Jun-2017
17-Jun-2017
yeah - but in the default property....
As Ajax said, in the Default Property, any Function used without the following () will be converted to a string...so
Cdate("01/01/" & year(Date))
will change to
Cdate("01/01/" & year("Date"))
Elsewhere is another thing entirely.
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007
That worked perfectly. Thanks to all.