I keep getting error code 13 - Type Mismatch

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use the "Year( #1/1/2005#)" Function where I replace the
"#1/1/2005#" value with a variable that is a date entered into a field called
[Start]. I have tried to define this variable as integer and and just about
every other data type there is, but I keep getting the "Type Mismatch"
message. the code looks like
Dim StartYear As Date
Dim x As Integer

StartYear = [Start] '[Start] is a "Date/Time" field
MsgBox ("StartYear = " & StartYear)
x = Year(StartYear)
MsgBox ("X is " & x)

I don't know what I am doing incorrectly, but for some reason I can't get
the thing to work.

Any help would be appreciated.
 
You could create a funtion to return the year portion of whatever date is
passed from your START field. You might try something like the following.

Public Function CalculateYear(Start As Date) As Integer
Dim x As Integer
x = Year([Start]) '[Start] is a "Date/Time" field)
MsgBox ("StartYear = " & x)
MsgBox ("X is " & x)
CalculateYear = x
End Function
 
Back
Top