Date Conversion in Query Parameter

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

Guest

I have a query where I generate a list of names if a two-digit year for a
year 2 years ago is found in a string in a text field. In the QBE grid, I use
the following criteria: Like "*" & "03" & "*". Works like a charm. But,
next year the criteria would be: Like "*" & "04" & "*".

I now want to generalize the query to avoid having to open up the query and
change the date. First try was: CStr(Right((Date-730),2)) as a replacement
for 03. Entire criteria was: Like "*" & CStr(Right((Date-730),2)) & "*".
Another try was: "*" & "CStr(Right((Date-730,2))" & "*". Records should have
been returned but were not in either case. Placed ?CStr(Right((Date-730),2))
in the Immediate Window and it returned the desired 03. Thus I must be using
quotes and asterisks incorrectly.

Your suggestions on the correct criteria would be greatly appreciated.
 
Thanks for the tip on using Format. I tinkered with your idea and found that
this worked: Right(Format(Year(Date())-2),2). The QBE grid would not accept
my use of two ## characters. Again, thanks for your fast response.
 
Back
Top