problem with Year function

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

Guest

I want to use the year() function to compare the year for an entered date
with another year (integer) value. No matter how I enter it, the year
function produces a type mismatch error. Even this, straight from the help
example:

dim yr as variant (or integer)
yr = Year(#04/01/2007#)

or Yr = year(date()) or yr = year(cdate("04/01/2007")) or yr =
Year(me.[date]) where [date] is a date field on the current form.

What am I missing?

DM
 
Odd, all of those examples you've posted work fine for me (as I'd expect
them to - there's nothing wrong with that code).

Can you post the full sub or function that this code appears in please?

Ed Metcalfe.
 
In
Dick Minter said:
I want to use the year() function to compare the year for an entered
date with another year (integer) value. No matter how I enter it,
the year function produces a type mismatch error. Even this,
straight from the help example:

dim yr as variant (or integer)
yr = Year(#04/01/2007#)

or Yr = year(date()) or yr = year(cdate("04/01/2007")) or yr =
Year(me.[date]) where [date] is a date field on the current form.

What am I missing?

Do you by any chance have a control, field, or variable named "Year",
whose name is in scope?
 
Yes; there is a interger field named "year" on a linked table and subform.
Is there a work around without renaming the field?
DM


Dirk Goldgar said:
In
Dick Minter said:
I want to use the year() function to compare the year for an entered
date with another year (integer) value. No matter how I enter it,
the year function produces a type mismatch error. Even this,
straight from the help example:

dim yr as variant (or integer)
yr = Year(#04/01/2007#)

or Yr = year(date()) or yr = year(cdate("04/01/2007")) or yr =
Year(me.[date]) where [date] is a date field on the current form.

What am I missing?

Do you by any chance have a control, field, or variable named "Year",
whose name is in scope?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
In
Dick Minter said:
Yes; there is a interger field named "year" on a linked table and
subform. Is there a work around without renaming the field?

The best solution would be to rename the field, as it may cause problems
later on. It's best to avoid all kinds of reserved words, to avoid just
this sort of issue. However, you may be able to work around it by
changing your code to explicitly specify that its the VBA function
you're referring to; e.g.,

yr = VBA.Year(me.[datefield])
 
For lists of reserved words:
http://office.microsoft.com/en-us/access/HP011353121033.aspx
http://support.microsoft.com/kb/248738/EN-US/
http://support.microsoft.com/default.aspx?scid=kb;en-us;209187
Allen Browne has provided a comprehensive list of reserved words that are
part of his Issue Checker utility. The list is here:
http://www.allenbrowne.com/AppIssueBadWord.html
Follow the Database Issue Checker Utility link to download the free utility,
which is very easy to use. Run it as soon as the basic design is complete,
then from time to time as the project progresses.

Dick Minter said:
Yes; there is a interger field named "year" on a linked table and subform.
Is there a work around without renaming the field?
DM


Dirk Goldgar said:
In
Dick Minter said:
I want to use the year() function to compare the year for an entered
date with another year (integer) value. No matter how I enter it,
the year function produces a type mismatch error. Even this,
straight from the help example:

dim yr as variant (or integer)
yr = Year(#04/01/2007#)

or Yr = year(date()) or yr = year(cdate("04/01/2007")) or yr =
Year(me.[date]) where [date] is a date field on the current form.

What am I missing?

Do you by any chance have a control, field, or variable named "Year",
whose name is in scope?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top