Hi I have a query is used for the control source of a report, Monthly
Statements
The query was running fine when it was simply showing all debits, now Ive
tried to adapt it by joining another table, transaction which stores details
of all customer payments, as well as supplier payments. Here is the original
query:
SELECT DISTINCT tblAccount.AccountIndex, tblSalesOrder.CustomerOrderNumber,
tblSalesInvoice.InvoiceDate, tblSalesInvoice.SalesInvoiceNumber,
tblSalesInvoice.TotalNett, tblVAT.VATValue, [TotalNett]*(([VatValue]/100)+1)
AS Debit
FROM tblVAT INNER JOIN ((tblAccount INNER JOIN tblSalesOrder ON tblAccount.
AccountIndex=tblSalesOrder.AccountIndex) INNER JOIN ((tblDespatch INNER JOIN
tblSalesOrderLine ON tblDespatch.SalesOrderNumber=tblSalesOrderLine.
SalesOrderNumber) INNER JOIN tblSalesInvoice ON tblDespatch.
DespatchNumber=tblSalesInvoice.[Despatch Number]) ON (tblSalesOrder.
SalesOrderNumber=tblDespatch.SalesOrderNumber) AND (tblSalesOrder.
SalesOrderNumber=tblSalesOrderLine.SalesOrderNumber)) ON tblVAT.
VATRate=tblSalesOrderLine.VATRate
ORDER BY tblAccount.AccountIndex, tblSalesInvoice.InvoiceDate;
After adapting it to 'supposedly' show the details of any payments
it now looks like :
SELECT DISTINCT tblAccount.AccountIndex, tblSalesOrder.CustomerOrderNumber,
tblSalesInvoice.InvoiceDate, tblSalesInvoice.SalesInvoiceNumber,
tblSalesInvoice.TotalNett, tblVAT.VATValue, [TotalNett]*(([VatValue]/100)+1)
AS Debit, tblTransaction.TypeOfPosting, IIf([TypeOfPosting]="Customer
Payment",[Amount],0) AS Credit
FROM tblTransaction INNER JOIN (tblVAT INNER JOIN ((tblAccount INNER JOIN
tblSalesOrder ON tblAccount.AccountIndex = tblSalesOrder.AccountIndex) INNER
JOIN ((tblDespatch INNER JOIN tblSalesOrderLine ON tblDespatch.
SalesOrderNumber = tblSalesOrderLine.SalesOrderNumber) INNER JOIN
tblSalesInvoice ON tblDespatch.DespatchNumber = tblSalesInvoice.[Despatch
Number]) ON (tblSalesOrder.SalesOrderNumber = tblSalesOrderLine.
SalesOrderNumber) AND (tblSalesOrder.SalesOrderNumber = tblDespatch.
SalesOrderNumber)) ON tblVAT.VATRate = tblSalesOrderLine.VATRate) ON
tblTransaction.TransactionNumber = tblSalesInvoice.TransactionNumber
ORDER BY tblAccount.AccountIndex, tblSalesInvoice.InvoiceDate;
The query works but only showing the records that have had a payment. I know
this is because of the INNER JOIN, but could anybody tell me is there a way
to display the result of the first query as well as being able to display any
payment details made from the transaction table??
Thank you
Ken Snell (MVP) - 26 Mar 2006 19:44 GMT
In the QBE window for the query in design view, right-click on the join line
between the two tables of interest. Select Edit from the menu. Choose the
option that allows all records from the parent table, and just the matching
records from the child table. Click OK.

Signature
Ken Snell
<MS ACCESS MVP>
> Hi I have a query is used for the control source of a report, Monthly
> Statements
[quoted text clipped - 55 lines]
>
> Thank you
graeme34 - 26 Mar 2006 20:15 GMT
Thank you Ken ! (and John)
>In the QBE window for the query in design view, right-click on the join line
>between the two tables of interest. Select Edit from the menu. Choose the
[quoted text clipped - 6 lines]
>>
>> Thank you
John Spencer - 26 Mar 2006 19:49 GMT
You might try changing the join to an outer join. TEST the following which uses
a right join. If this works it will return all records in the other tables.
SELECT DISTINCT tblAccount.AccountIndex, tblSalesOrder.CustomerOrderNumber,
tblSalesInvoice.InvoiceDate, tblSalesInvoice.SalesInvoiceNumber,
tblSalesInvoice.TotalNett, tblVAT.VATValue, [TotalNett]*(([VatValue]/100)+1)
AS Debit, tblTransaction.TypeOfPosting, IIf([TypeOfPosting]="Customer
Payment",[Amount],0) AS Credit
FROM tblTransaction RIGHT JOIN (tblVAT INNER JOIN ((tblAccount INNER JOIN
tblSalesOrder ON tblAccount.AccountIndex = tblSalesOrder.AccountIndex) INNER
JOIN ((tblDespatch INNER JOIN tblSalesOrderLine ON tblDespatch.
SalesOrderNumber = tblSalesOrderLine.SalesOrderNumber) INNER JOIN
tblSalesInvoice ON tblDespatch.DespatchNumber = tblSalesInvoice.[Despatch
Number]) ON (tblSalesOrder.SalesOrderNumber = tblSalesOrderLine.
SalesOrderNumber) AND (tblSalesOrder.SalesOrderNumber = tblDespatch.
SalesOrderNumber)) ON tblVAT.VATRate = tblSalesOrderLine.VATRate) ON
tblTransaction.TransactionNumber = tblSalesInvoice.TransactionNumber
ORDER BY tblAccount.AccountIndex, tblSalesInvoice.InvoiceDate;
> Hi I have a query is used for the control source of a report, Monthly
> Statements
[quoted text clipped - 46 lines]
> --
> Message posted via http://www.accessmonster.com