What's wrong with this?? :
Private Sub Form_Load()
Dim mydate As String
mydate = YEAR(Date)
End Sub
It is giving me type-mismatch at mydate = Year(date) line.
What's wrong with this?? :
Private Sub Form_Load()
Dim mydate As String
mydate = YEAR(Date)
End Sub
It is giving me type-mismatch at mydate = Year(date) line.
Year(Date) returns a numeric value, not a string.
Either declare Mydate as integer, or use str(year(date)) to force it to string type.
I should point out that that sub is essentially useless anyway. Because you declare mydate inside the sub, it is known only to that sub, and not outside it.
What is it you want to do in the Load event?
John
Last edited by John_G; 03-27-2012 at 10:11 PM. Reason: Additional comment
Hi John,
The problem is that year(date) expression returns type mismatch - I see that when I add this expression to the watch window..
Regarding this sub, it isnt really the full code... i have a long code in this form load event sub. But I need to compare year of a date_field to today's year. I couldn't get that to work and in process of debugging that I found that just the expression of year(date) isnt working.
I also tried doing Cstr(year(date)) and also Cstr(year(datevalue(date))) and neither of them works....
Shot in the dark warning. You don't have field named date do you?
nope, i dont have field called date
see the attached screenshot. it shows all the expressions i have added to the watch window and how year(date) returns type mismatch.
seems like the insert image isnt working... so ignore the previous post...
btw, this is exactly same problem as mine... http://www.tek-tips.com/viewthread.cfm?qid=411627
anyway, I found it... I somehow had a hidden textbox whose name was year.... thanks Paul for putting me in the right direction.