Share via

Birthday & Anniversary Queries

Anonymous
2012-10-11T20:14:28+00:00

Every year I have to schedule email cards to be sent to our 500 members for their birthdays and anniversaries. I need a query that displays the name, email, and birthday or anniversary (these queries would be separate). The birthdays or anniveraries need to be grouped by month, then day. The year or age of the person is irrelevant.

It appears that you can only order the birthdays chronologically.

Is there a way I can set this up?

Appreciate any help you can give.

Melissa

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-10-11T20:41:10+00:00

It appears that you can only order the birthdays chronologically.

Is there a way I can set this up?

 

Yes if you are using a DateTime field by having 2 calculated fields to sort on as below --

My_Month:   Month([BirthDate])     My_Day:   Day([BirthDate])

My_Month: Month([MarriedDate]) My_Day: Day([MarriedDate])

    Or for single field -- 

My_BirthDate: Format([BirthDate], "mmdd")   My_Married: Format([MarriedDate], "mmdd")

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-10-13T12:32:33+00:00

    If you sort by the birthday or anniversary month/days as separate columns one will have to take precedence over the other of course.  A better way might possibly be to return both as a single column.  That way if someone has a birthday in February say, but an anniversary in September the query will return two rows for that member, one sorted amongst the February dates, the other amongst the September dates.  You can do this by means of a UNION ALL operation, e.g.

    SELECT FirstName, LastName, EmailAddress,

    "Birthday" AS AnniversaryType,

    FORMAT(BirthDate,"dd mmmm") AS AnniversaryDate,

    FORMAT(BirthDate,"mmdd") AS SortColumn

    FROM Members

    WHERE BirthDate IS NOT NULL

    UNION ALL

    SELECT FirstName, LastName, EmailAddress,

    "Anniversary", FORMAT(MarriageDate,"dd mmmm"),

    FORMAT(MarriageDate,"mmdd")

    FROM Members

    WHERE MarriageDate IS NOT NULL

    ORDER BY SortColumn;

    As Karl said, you don't need to create any calculated fields in the table.  You can't create a UNION query visually in query design view, only in SQL view, so open the query designer as if designing a new query, switch to SQL view and paste in the above SQL statement in place of what's there.  Then edit it, changing the table and column names to the actual names of your table and columns.  Remember that table or column names which include spaces or other special characters must be wrapped in square brackets, e.g. [Marriage Date].  Note that the string expressions "Birthday" and "Anniversary" as the AnniversaryType column are constants, so don't change these.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-10-13T01:10:19+00:00

    I created 4 new calculated fields in my table like you said and then was able to add them to my query instead of the actual Date/Time field of the occasion.

    The calculated fields are not to be in the table but in your query.  Your table to have 2 DateTime fields for birthday and wedding.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-10-12T15:35:28+00:00

    Thank you!

    I'm not sure if I interpretted this correctly but I got the result I was looking for.

    I created 4 new calculated fields in my table like you said and then was able to add them to my query instead of the actual Date/Time field of the occasion.

    After that, I was able to sort them in ascending order by month, then day.

    PERFECT!!! Happy dance! This is why I switched our database to access! Four years of frustration is over:)

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-10-11T20:34:59+00:00

    In your query add a column as Month([DateField]).  This will all grouping by the month.

    Month(#10/11/2012#) returns 10.

    You can also use Format.

     Format(#10/11/2012#,"m") returns 10.

    Format(#10/11/2012#,"mmm") returns Oct.

    Format(#10/11/2012#,"mmmm") returns October.

    Jack

    Was this answer helpful?

    0 comments No comments