Hi, Joy.
You asked me in another thread to take a look at your date formatting
problem for your UNION query. Sorry I took so long. The queries were the
easy part, but I also wanted to explain the "how" so that you'll understand
it better.
Part 1-How do I get the union query to be medium date (like the table)?
Use the Format( ) function with "medium date" as the parameter. For example:
Format([BIRTH DA], "medium date")
Part 2 -I want to sort so that any event on January 1 is followd by any
events on January 2...., reguardless of the year. How do I write the
forumula?
You'll need to identify the month and day of each date, place them each in
separate columns, and then sort the query on those two columns. For example,
the DatePart( ) method can provide the month, in digits:
DatePart("m", [BIRTH DA])
From the other thread, here's your query with these changes:
SELECT Format([BIRTH DA], "medium date") AS EDate,
[CALLED] & " " & [LAST NAME] AS who,
DatePart("m", [BIRTH DA]) AS Mo,
DatePart("d", [BIRTH DA]) AS Da
FROM DCC
WHERE [BIRTH DA] IS NOT NULL
UNION ALL
SELECT Format([WED DA], "medium date"),
(Called & " & " & Spouse & " " & [LAST NAME]) AS Couple,
DatePart("m", [WED DA]) AS Mo,
DatePart("d", [WED DA]) AS Da
FROM (SELECT IIf((P.ID>S.ID),P.ID,S.ID) AS Cut
FROM qryFindNearDuplicates AS P INNER JOIN
qryFindNearDuplicates AS S ON (P.Pair=S.Swap)
AND (P.[LAST NAME]=S.[LAST NAME])) AS Q
RIGHT JOIN DCC ON Q.Cut = DCC.ID
WHERE (ISNULL(Cut) = TRUE) AND [WED DA] IS NOT NULL
ORDER BY 3, 4;
.. . . where ID is assumed to be the name of the primary key in your table
(you'll need to replace it with the name of your primary key that used to be
named "Index"). However, this displays two extra calculated columns in your
query, Mo and Da. If this is not acceptable, then you can use an interim
query so that the final query only displays what you want, the date of the
event, and the "who" of the event. Save the following SQL statement in the
SQL View pane, and name it qryEvents:
SELECT Format([BIRTH DA], "medium date") AS EDate,
[CALLED] & " " & [LAST NAME] AS who,
DatePart("m", [BIRTH DA]) AS Mo,
DatePart("d", [BIRTH DA]) AS Da
FROM DCC
WHERE [BIRTH DA] IS NOT NULL
UNION ALL
SELECT Format([WED DA], "medium date"),
(Called & " & " & Spouse & " " & [LAST NAME]) AS Couple,
DatePart("m", [WED DA]) AS Mo,
DatePart("d", [WED DA]) AS Da
FROM (SELECT IIf((P.ID>S.ID),P.ID,S.ID) AS Cut
FROM qryFindNearDuplicates AS P INNER JOIN
qryFindNearDuplicates AS S ON (P.Pair=S.Swap)
AND (P.[LAST NAME]=S.[LAST NAME])) AS Q
RIGHT JOIN DCC ON Q.Cut = DCC.ID
WHERE (ISNULL(Cut) = TRUE) AND [WED DA] IS NOT NULL;
This is the interim query. You might notice that it's identical to the
earlier query, but it has no sorted columns. The sorting will be done in the
final query.
And just to clarify a little bit further on the matter of duplicates (or
near duplicates) in the table, due to the unnormalized structure of the
table, the second half of the UNION query (for the wedding dates) is
specially designed to eliminate these duplicates. However, the first half of
the UNION query (for the birthdates) doesn't eliminate duplicates because you
weren't complaining of duplicate birthdates, so that part of the query was
left as is. And when you look at the two halves of the query, you can see
that fixing the structure of the table would prevent having to create a
convoluted query just to display the data correctly. If you want help and
have the time to fix this problem, please post new questions asking how to
normalize the table, and how to change any of the queries you have already
created to accommodate this unnormalized table into queries for the new table
structure.
For the final query, create a new query and paste the following into the SQL
View pane:
SELECT EDate, who
FROM qryEvents
ORDER BY 3, 4;
Part 3-Where do I find properties so that I can change union queries?
The field properties that you've asked about are so that you can format the
dates, but that's not available in UNION queries, as you've already found
out. The solution is to use the Format( ) method in the SQL statement as
shown above.
If you have any further problems with this query, please post back.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.