How do I query a Date field (mm/dd/yyyy) by a Year (yyyy) value.

  • Thread starter Thread starter Wayne
  • Start date Start date
W

Wayne

I'm trying to execute a query which contains a date field (mm/dd/yyyy)
where the criteria for that date field is a value entered in a form text
box (yyyy).

But obviously it doesn't work. I even tried using Like
[Forms]![Form1]![Year], but that doesn't work either.

There's got to be a more efficient way of doing this, besides creating a
separate Year field to query on instead.

Any ideas?
 
two options,, one of which is to create another field for Year, like you
said.

The only other way I can see would be for the criteria to read:

between DateValue("1/1/"&[YearFromForm]) and
DateValue("12/31/"&[YearFromForm])

As to whether this is more efficient, who knows? try it both ways and
time it...
 
Try criteria like the following:

Between DateSerial([Forms]![Form1]![Year],1,1) And DateSerial([Forms]![Form1]![Year],12,31)
two options,, one of which is to create another field for Year, like you
said.

The only other way I can see would be for the criteria to read:

between DateValue("1/1/"&[YearFromForm]) and
DateValue("12/31/"&[YearFromForm])

As to whether this is more efficient, who knows? try it both ways and
time it...
I'm trying to execute a query which contains a date field (mm/dd/yyyy)
where the criteria for that date field is a value entered in a form text
box (yyyy).

But obviously it doesn't work. I even tried using Like
[Forms]![Form1]![Year], but that doesn't work either.

There's got to be a more efficient way of doing this, besides creating a
separate Year field to query on instead.

Any ideas?
 
Back
Top