Gasman
Enthusiastic Amateur
- Local time
- Today, 20:03
- Joined
- Sep 21, 2011
- Messages
- 16,449
Hi all,
I have created a small Access system to generate a few excel sheets.
I was quite happy with the way it was progressing and it even showed me a few errors in my current Excel processing of the data.
The relationship diagram is attached. I know it is not perfect, but I hope I am getting there.
Now currently it only needs to produce two sheets. One for which I call Invoice and another for Updates.
Updates are details of all trades for the respective company and include those that earn commission and those that do not.
As not every trade earns commission, I only create commission records for those that do.
I also had the requirement to have to split the commission between individuals in the company and this was becoming unwieldy in Excel and that is why I decide to try in Access.
My SQL for Updates is
This works fine for when there is only one submitter for a company. It produces both those records that have commissions attached and those that do not.
However when I apply it to a company that has more than 1, in this case 2 submitters, it doubles up the records that have commissions. I dare say it the company had three, it would triple the number. If I put a further check in for SubmitterClientId, I get only the correct records, but miss out on those records that do not have commission attached.
I *think I need a union somewhere, but not sure on how to code it.?
I'd appreciate some pointers on how to overcome this.
I'm fine (I think) with the Invoicing part as that looks for specific dates and of course only includes records that have commission, but notice I do have the submitterclientid in the string as well.
TIA
I have created a small Access system to generate a few excel sheets.
I was quite happy with the way it was progressing and it even showed me a few errors in my current Excel processing of the data.
The relationship diagram is attached. I know it is not perfect, but I hope I am getting there.
Now currently it only needs to produce two sheets. One for which I call Invoice and another for Updates.
Updates are details of all trades for the respective company and include those that earn commission and those that do not.
As not every trade earns commission, I only create commission records for those that do.
I also had the requirement to have to split the commission between individuals in the company and this was becoming unwieldy in Excel and that is why I decide to try in Access.
My SQL for Updates is
Code:
strSQL = "SELECT tblSVSTrades.TradeDate, tblClient.Forename, tblClient.Surname, tblSVSTrades.TradeType, tblSVSTrades.NetCost, tblSVSTrades.BuySell, tblSubmitter.SubmitterName,tblIntroCommission.IntroCommission, tblIntroCommission.InvoicedDate, tblIntroCommission.PaidDate FROM (tblCommission"
strSQL = strSQL & " RIGHT JOIN ((tblClient INNER JOIN (tblSubmitter INNER JOIN tblSubmitterClient ON tblSubmitter.SubmitterID = tblSubmitterClient.SubmitterID) ON tblClient.ClientID = tblSubmitterClient.ClientID)"
strSQL = strSQL & " INNER JOIN tblSVSTrades ON tblClient.SVS_Account = tblSVSTrades.SVSAccount) ON tblCommission.TradeID = tblSVSTrades.SVSTradesID) LEFT JOIN tblIntroCommission ON tblCommission.CommissionID = tblIntroCommission.CommissionID"
strSQL = strSQL & " WHERE (((tblSubmitter.SubmitterID)=" & lngSubmitterID & " ))"
strSQL = strSQL & " ORDER BY tblSVSTrades.SVSTradesID"
This works fine for when there is only one submitter for a company. It produces both those records that have commissions attached and those that do not.
However when I apply it to a company that has more than 1, in this case 2 submitters, it doubles up the records that have commissions. I dare say it the company had three, it would triple the number. If I put a further check in for SubmitterClientId, I get only the correct records, but miss out on those records that do not have commission attached.
I *think I need a union somewhere, but not sure on how to code it.?
I'd appreciate some pointers on how to overcome this.
I'm fine (I think) with the Invoicing part as that looks for specific dates and of course only includes records that have commission, but notice I do have the submitterclientid in the string as well.
Code:
strSQL = "SELECT tblSVSTrades.TradeDate, tblSVSTrades.Forename, tblSVSTrades.Surname, tblSVSTrades.TradeType, tblSVSTrades.NetCost, tblSVSTrades.BuySell, tblSubmitter.SubmitterName, tblIntroCommission.IntroCommission,tblIntroCommission.Invoiceddate,tblIntroCommission.PaidDate FROM tblSubmitter"
strSQL = strSQL & " INNER JOIN (tblSubmitterClient INNER JOIN ((tblCommission INNER JOIN tblIntroCommission ON tblCommission.CommissionID = tblIntroCommission.CommissionID) INNER JOIN tblSVSTrades ON tblCommission.TradeID = tblSVSTrades.SVSTradesID) ON tblSubmitterClient.SubmitterClientID = tblIntroCommission.SubmitterClientID) ON tblSubmitter.SubmitterID = tblSubmitterClient.SubmitterID"
strSQL = strSQL & " WHERE (((tblIntroCommission.InvoicedDate) = " & strSQLDate & ") AND ((tblSubmitterClient.SubmitterID)= " & lngSubmitterID & "))"
strSQL = strSQL & " ORDER BY tblSVSTrades.SVSTradesID;"
TIA