Teri:
The fundamental problem is that while you are declaring a start date
parameter you are not actually restricting the result set with it, so even
though you are entering the date when prompted its having no effect.
There are one or two other points about the query, which are not
contributing to the problem, but nevertheless would be best corrected:
1. The query is adding "1" to the end date as a string (its delimited with
quotes) not as a number (which doesn’t need to be delimited).
2. The query is being restricted by a HAVING Clause not a WHERE clause.
This results from putting the criteria under the GROUP BY columns in design
view and is a very common mistake. When using design view what should be
done to create a WHERE clause is to add the Last Name and Date Received
columns twice to the grid. In one of each select WHERE from the 'total'
row's drop down list, uncheck the 'show' check box and put the criteria in
those columns not the GROUP BY ones. The difference is that a WHERE clause
acts on the data before its grouped, a HAVING clause after its grouped. The
latter is normally used to restrict a query on the basis of a group of rows,
e.g. if the average value of orders by a customer is > 1000 in a
GetGoodCustomers query.
So taking these points into account the SQL should look like this:
PARAMETERS [Enter Start Date:] DateTime, [Enter End Date:] DateTime;
SELECT Contacts.[Last Name], Contacts.[First Name],
[Payment Information].[Date Received],
Sum([Payment Information].[Amount Payment Type 1]) AS [SumOfAmount Payment
Type 1], Sum([Payment Information].[Amount Payment Type 2]) AS [SumOfAmount
Payment Type 2]
FROM Contacts INNER JOIN [Payment Information]
ON Contacts.[Last Name] = [Payment Information].[Last Name]
WHERE Contacts.[Last Name] = [Enter Name])
AND [Payment Information].[Date Received] >=[Enter Start Date:]
AND [Payment Information].[Date Received] <[Enter End Date:]+1
GROUP BY Contacts.[Last Name], Contacts.[First Name], [Payment
Information].[Date Received];
Copy this to the clipboard and paste it in to the query in SQL view in place
of the existing SQL and it should work.
Incidentally I see you are joining the tables on the LastName columns.
Names don't make good keys as they are not necessarily unique. Even
combinations of first and last names can be duplicated; I used to work with
two Maggie Taylors. Its much better to use a numeric key such as ContactID.
In the contacts table this can be an autonumber, but in the Payment
Information table it would be a long integer number data type. If you add
these columns to the tables the ContactID in Contacts would be filled
automatically, and you can easily populate the foreign key ContactID in
Payment Information with an update query:
UPDATE [Payment Information] INNER JOIN Contacts
ON [Payment Information].[Last Name] = Contacts.[Last Name]
SET [Payment Information].ContactID = [Contacts].[ContactID];
After running this query and satisfying yourself that the ContactID values
are correct you can delete the Last Name column from payment Information.
Each contact is now uniquely identified even if two have the same names.
I think I'll stay a dog. They have more fun than gems who just sit around
looking pretty all day!
Ken Sheridan
Stafford, England
Teri said:
Ken,
Here is what I found in the SQL view:
PARAMETERS [Enter Start Date:] DateTime, [Enter End Date:] DateTime;
SELECT Contacts.[Last Name], Contacts.[First Name], [Payment
Information].[Date Received], Sum([Payment Information].[Amount Payment Type
1]) AS [SumOfAmount Payment Type 1], Sum([Payment Information].[Amount
Payment Type 2]) AS [SumOfAmount Payment Type 2]
FROM Contacts INNER JOIN [Payment Information] ON Contacts.[Last Name] =
[Payment Information].[Last Name]
GROUP BY Contacts.[Last Name], Contacts.[First Name], [Payment
Information].[Date Received], [Payment Information].[Last Name]
HAVING (((Contacts.[Last Name])=[Enter Name]) AND (([Payment
Information].[Date Received])<[Enter End Date:]+"1 "))
ORDER BY Contacts.[Last Name];
None of this makes much sense to me, at least not at this point. I am hopin
it will someday.
Gems are also quite bright and usually worth a lot more than they appear at
first glance, still want to be a dog?
Teri.