Type Mismatch

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

Hello,

In the following code,


If IsNull([txtYear]) Or [txtYear] = "" Then
[txtYear] = Year(Date)
Else
[txtYear] = [Year] + 1
End If

the expression Year(Date) gives me a type mismatch message when I place the
mouse pointer over the expression in the debug window.

When I execute ?Year(Date) in the immediate window, it returns 2005.
Date returns the date.

This doesn't make sense since Year() and Date() are public functions.

Thanks for any help.

Mark A.Sam
 
Mark A. Sam said:
Hello,

In the following code,


If IsNull([txtYear]) Or [txtYear] = "" Then
[txtYear] = Year(Date)
Else
[txtYear] = [Year] + 1
End If

the expression Year(Date) gives me a type mismatch message when I
place the mouse pointer over the expression in the debug window.

When I execute ?Year(Date) in the immediate window, it returns
2005. Date returns the date.

This doesn't make sense since Year() and Date() are public functions.

Thanks for any help.

Mark A.Sam

Hi Mark,

From Help on Year()
Returns a Variant (Integer) containing a whole number representing the
year.

How about [txtYear] = Str(Year(Date))

and it looks like you may have problems a couple of lines down:

[txtYear] = [Year] + 1

should probable be [txtYear] = Str(Year(Date) + 1)

HTH
 
Hi Mark,

Usually it's a good idea not to give fields and other objects the same
names as common properties and functions (e.g. Name, Date, Year). Try
renaming your Year field to (e.g.) TheYear.


Hello,

In the following code,


If IsNull([txtYear]) Or [txtYear] = "" Then
[txtYear] = Year(Date)
Else
[txtYear] = [Year] + 1
End If

the expression Year(Date) gives me a type mismatch message when I place the
mouse pointer over the expression in the debug window.

When I execute ?Year(Date) in the immediate window, it returns 2005.
Date returns the date.

This doesn't make sense since Year() and Date() are public functions.

Thanks for any help.

Mark A.Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top