You can use criteria against the string
Field: Format([YOUR DOB FIELD HERE],"mmdd")
Criteria: Like "05*"
If you wish you can use a parameter prompt in the criteria.
Criteria: Like Format([Enter month Number],"00") & "*"
IF you use that expression you can enter 1 to 12 and should get the
corresponding month.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Susan May wrote:
ok, that worked. Now, how do I only get the birthdays for the month of
May?
Can I add to this string?
Thanks
Susan
:
Sorry, I pressed the wrong key.
That expression goes into a Field "cell" not into a criteria "cell".
Also
make sure you are using your field name not one I made up for purposes
of
illustration.
BirthdaySort: Format([YOUR DOB FIELD HERE],"mmdd")
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Susan May wrote:
I don't know what I'm doing wrong John, but I put the expression in
the
criteria line and it says data type mismatch in criteria expression.
Format("DOBBirthday", "mmdd") is what it shows after I run the query.
I
tried the calculated field too and it says "Enter paramater value.
In the
field line I have
BirthdaySort: Format([DOBBirthday],"mmdd")
What am I doing wrong?
:
Use the following expression to sort by
FORMAT(DOBField,"mmdd")
That will yield dates like 0409 (April 9th) and 1212 (December 12th)
Note that you don't have to display the field in this manner. You
can have an
additional calculated field that is
Format(DOBField,"d mmm")
This will return dates that look like 9 Apr and 12 Dec
and display this calculated field.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Susan May wrote:
John: I have a different problem.
I have 660 reps who get birthday choclates each month. The
birthday field
is date/time field, so when I do Like "5*", I get all the reps with
a
birthday in May, but it sorts by the year they were born. The
company wants
all reps that were born each month, sorted by the day of the month.
How can I incorporate that into one expression so it sorts only
monthly by
the day of the month?
Many thanks.
Susan
:
On Wed, 22 Aug 2007 05:52:03 -0700, Bunky
<
[email protected]>
wrote:
John,
Thanks for the heads up on what it is expecting. Unfortunately,
I first
take the reservation date and format it to an interval week/yr by
this
expression in a prior query.
Res Week&Year: Format([Res-Date],"yy") &
Format(Format([Res-Date],"mm"),"00")
Why? You're THROWING AWAY DATA unnecessarily.
Note that if you want to do this (and again, it's not necessary)
you could use
a single format statement. For month and year, just use
Format([Res-date], "yymm").
But it *is not necessary* to do this for matching purposes. You
can use a
range of dates for matching; e.g. to find all the reservations in
June 2007,
you could use a query criterion on [Res-date] of
BETWEEN DateSerial([Enter year:], [Enter month number:], 1) AND
DateSerial([Enter year:], [Enter month number:]+1, 0)
This criterion will make use of indexes on the date field so it
will run
faster.
Then after I do matching on the interval date of Res Week&Year, I
would like
to display on a report the Alpha information as previous
discussed. So how
do I get
Access to recognize this as a Date/Time function?
By applying it to a date/time field (Res-Date) rather than
converting the date
to a number, the number to a string, the string to another string,
the string
to a number...
I can see how you got painted into this corner, but it is *NOT*
necessary to
have all these conversions!
John W. Vinson [MVP]