tags:

views:

51

answers:

1

To keep this simple, lets say I have two tables.

The first is called Employees. It contains an id field and an employee_name field.

The second is called Pay. It contains an id field, an employee_id field and an amount field.

Now, I want to run a report on Pay that shows me how much each employee got paid by showing me only the Employee.employee_name and the Pay.amount.

Obviously, I'm going to have to take the employee_id field from the Pay table and match it up with the the id field from Employees, but I have no idea how to do that.

I know a little VBA and am pretty knowledgeable with SQL, but MS Access has me so confused I'm about to kill myself. I hate Access so much, I want to take it outside behind the middle school and get it dead.

This seems like a relatively easy problem, so someone has to know how to do this. Any help would be hugely appreciated.

+1  A: 

You are looking for a query like this

SELECT Employees.Id, 
       Employees.employee_name, 
       Sum(Pay.amount) AS SumOfamount
FROM   Pay INNER JOIN 
       Employees ON Pay.employee_id = Employees.Id
GROUP BY  Employees.Id, 
          Employees.employee_name;

If you wish to make this as part of a list box, you can either save the sql as a query and set the Listbox property under the Data Tab called RowSource to the Saved Query Name, or you can set the sql string as the RowSource.

Remember to have a look at the Properties called Column Count ( something like 0;3;3 0 being to hide the first column ) and Column Heads (to include column headers, default NO )

If you widh to craete a Report using the data, you can go about this the same way ( Saved Query or Use the Sql String ). The Query/Sql String can be set in the Data Tab in the Record Source property. Now you can add the fields to the report from the Existing Fields window.

astander
That may be the SQL, but it seems like the original questioner is unlikely to know what to do with it. I'll vote up your answer if you provide that detail.
David-W-Fenton