Greetings,
I am receiving a "Query too complex" error when I am attempting to run one of my queries and it is a result of a complex argument passed to a field in my query via vba. Below are two examples of my data. "Example 1" is a simple example of the original data that lies in one of my data tables. "Example 2" is how I would like to report this data via a query.
<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="font-weight: bold;color: #FF0000;;">EXAMPLE_1:</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="font-weight: bold;;">Advertiser</td><td style="font-weight: bold;;">Start Date</td><td style="font-weight: bold;;">End Date</td><td style="font-weight: bold;;">Booked Revenue</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style=";">Ford</td><td style="text-align: right;;">1/1/2011</td><td style="text-align: right;;">3/15/2011</td><td style="text-align: right;;"> $ 10,000 </td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style=";">Toyota</td><td style="text-align: right;;">2/5/2011</td><td style="text-align: right;;">10/15/2011</td><td style="text-align: right;;"> $ 30,000 </td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style=";">Audi</td><td style="text-align: right;;">2/1/2011</td><td style="text-align: right;;">4/30/2011</td><td style="text-align: right;;"> $ 25,000 </td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet1</p><br /><br />
<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th><th>G</th><th>H</th><th>I</th><th>J</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">9</td><td style="font-weight: bold;border-bottom: 1px solid black;color: #FF0000;;">EXAMPLE_2:</td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;background-color: #F2F2F2;;">Advertiser</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">Start Date</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">End Date</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">Booked Revenue</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">1/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">2/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">3/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">4/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">5/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-right: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">Total</td></tr><tr ><td style="color: #161120;text-align: center;">11</td><td style="border-top: 1px solid black;border-left: 1px solid black;;">Ford</td><td style="text-align: right;border-top: 1px solid black;;">1/1/2011</td><td style="text-align: right;border-top: 1px solid black;;">3/15/2011</td><td style="text-align: right;border-top: 1px solid black;;"> $ 10,000 </td><td style="text-align: right;border-top: 1px solid black;;"> 4,189.19 </td><td style="text-align: right;border-top: 1px solid black;;"> 3,783.78 </td><td style="text-align: right;border-top: 1px solid black;;"> 2,027.03 </td><td style="text-align: right;border-top: 1px solid black;;"> - </td><td style="text-align: right;border-top: 1px solid black;;"> - </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-right: 1px solid black;;"> 10,000.00 </td></tr><tr ><td style="color: #161120;text-align: center;">12</td><td style="border-left: 1px solid black;;">Toyota</td><td style="text-align: right;;">2/5/2011</td><td style="text-align: right;;">5/30/2011</td><td style="text-align: right;;"> $ 30,000 </td><td style="text-align: right;;"> - </td><td style="text-align: right;;"> 6,260.87 </td><td style="text-align: right;;"> 8,086.96 </td><td style="text-align: right;;"> 7,826.09 </td><td style="text-align: right;;"> 7,826.09 </td><td style="font-weight: bold;text-align: right;border-right: 1px solid black;;"> 30,000.00 </td></tr><tr ><td style="color: #161120;text-align: center;">13</td><td style="border-bottom: 1px solid black;border-left: 1px solid black;;">Audi</td><td style="text-align: right;border-bottom: 1px solid black;;">2/1/2011</td><td style="text-align: right;border-bottom: 1px solid black;;">4/30/2011</td><td style="text-align: right;border-bottom: 1px solid black;;"> $ 25,000 </td><td style="text-align: right;border-bottom: 1px solid black;;"> - </td><td style="text-align: right;border-bottom: 1px solid black;;"> 7,865.17 </td><td style="text-align: right;border-bottom: 1px solid black;;"> 8,707.87 </td><td style="text-align: right;border-bottom: 1px solid black;;"> 8,426.97 </td><td style="text-align: right;border-bottom: 1px solid black;;"> - </td><td style="font-weight: bold;text-align: right;border-right: 1px solid black;border-bottom: 1px solid black;;"> 25,000.00 </td></tr><tr ><td style="color: #161120;text-align: center;">14</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;background-color: #DBEEF3;;">Total</td><td style="text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"></td><td style="text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"></td><td style="text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"></td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 4,189.19 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 17,909.82 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 18,821.85 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 16,253.05 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 7,826.09 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 65,000.00 </td></tr><tr ><td style="color: #161120;text-align: center;">15</td><td style="text-align: center;border-top: 1px solid black;;">*** example of how we need to convert the data via a query into the above format… booked revenue broken out by month. This is done by pro-rating based on days in month and length of campaign</td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td></tr><tr ><td style="color: #161120;text-align: center;">16</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td></tr><tr ><td style="color: #161120;text-align: center;">17</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet1</p><br /><br />
In "Example 2" ws cell E11 the following excel formula exists:
This formula is used to determine if the order start date and end date applies to the given month (header) and if so pro-rate the total cost of the order to the month based on the number of days.
I have build an Access Query that dynamically builds out a table similar to "Example 2" above based on "Example 1" data table, however I need help simplifying my formula noted above... it seems to be too complex, it works in Excel but too complex for Access to handle. Below is the same code for one of my data fields but configured for VB and SQL which is passed to each field in my query:
Does anyone have any suggestions regarding how to simplify this formula/code or other methods of obtaining my desired results evident in "Example 2"?
Thanks in advance for your help... I've hit a road block LOL
I am receiving a "Query too complex" error when I am attempting to run one of my queries and it is a result of a complex argument passed to a field in my query via vba. Below are two examples of my data. "Example 1" is a simple example of the original data that lies in one of my data tables. "Example 2" is how I would like to report this data via a query.
<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="font-weight: bold;color: #FF0000;;">EXAMPLE_1:</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="font-weight: bold;;">Advertiser</td><td style="font-weight: bold;;">Start Date</td><td style="font-weight: bold;;">End Date</td><td style="font-weight: bold;;">Booked Revenue</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style=";">Ford</td><td style="text-align: right;;">1/1/2011</td><td style="text-align: right;;">3/15/2011</td><td style="text-align: right;;"> $ 10,000 </td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style=";">Toyota</td><td style="text-align: right;;">2/5/2011</td><td style="text-align: right;;">10/15/2011</td><td style="text-align: right;;"> $ 30,000 </td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style=";">Audi</td><td style="text-align: right;;">2/1/2011</td><td style="text-align: right;;">4/30/2011</td><td style="text-align: right;;"> $ 25,000 </td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet1</p><br /><br />
<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th><th>G</th><th>H</th><th>I</th><th>J</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">9</td><td style="font-weight: bold;border-bottom: 1px solid black;color: #FF0000;;">EXAMPLE_2:</td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td><td style="text-align: right;border-bottom: 1px solid black;;"></td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;background-color: #F2F2F2;;">Advertiser</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">Start Date</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">End Date</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">Booked Revenue</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">1/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">2/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">3/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">4/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">5/1/2011</td><td style="font-weight: bold;text-align: center;border-top: 1px solid black;border-right: 1px solid black;border-bottom: 1px solid black;background-color: #F2F2F2;;">Total</td></tr><tr ><td style="color: #161120;text-align: center;">11</td><td style="border-top: 1px solid black;border-left: 1px solid black;;">Ford</td><td style="text-align: right;border-top: 1px solid black;;">1/1/2011</td><td style="text-align: right;border-top: 1px solid black;;">3/15/2011</td><td style="text-align: right;border-top: 1px solid black;;"> $ 10,000 </td><td style="text-align: right;border-top: 1px solid black;;"> 4,189.19 </td><td style="text-align: right;border-top: 1px solid black;;"> 3,783.78 </td><td style="text-align: right;border-top: 1px solid black;;"> 2,027.03 </td><td style="text-align: right;border-top: 1px solid black;;"> - </td><td style="text-align: right;border-top: 1px solid black;;"> - </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-right: 1px solid black;;"> 10,000.00 </td></tr><tr ><td style="color: #161120;text-align: center;">12</td><td style="border-left: 1px solid black;;">Toyota</td><td style="text-align: right;;">2/5/2011</td><td style="text-align: right;;">5/30/2011</td><td style="text-align: right;;"> $ 30,000 </td><td style="text-align: right;;"> - </td><td style="text-align: right;;"> 6,260.87 </td><td style="text-align: right;;"> 8,086.96 </td><td style="text-align: right;;"> 7,826.09 </td><td style="text-align: right;;"> 7,826.09 </td><td style="font-weight: bold;text-align: right;border-right: 1px solid black;;"> 30,000.00 </td></tr><tr ><td style="color: #161120;text-align: center;">13</td><td style="border-bottom: 1px solid black;border-left: 1px solid black;;">Audi</td><td style="text-align: right;border-bottom: 1px solid black;;">2/1/2011</td><td style="text-align: right;border-bottom: 1px solid black;;">4/30/2011</td><td style="text-align: right;border-bottom: 1px solid black;;"> $ 25,000 </td><td style="text-align: right;border-bottom: 1px solid black;;"> - </td><td style="text-align: right;border-bottom: 1px solid black;;"> 7,865.17 </td><td style="text-align: right;border-bottom: 1px solid black;;"> 8,707.87 </td><td style="text-align: right;border-bottom: 1px solid black;;"> 8,426.97 </td><td style="text-align: right;border-bottom: 1px solid black;;"> - </td><td style="font-weight: bold;text-align: right;border-right: 1px solid black;border-bottom: 1px solid black;;"> 25,000.00 </td></tr><tr ><td style="color: #161120;text-align: center;">14</td><td style="font-weight: bold;border-top: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;background-color: #DBEEF3;;">Total</td><td style="text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"></td><td style="text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"></td><td style="text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"></td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 4,189.19 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 17,909.82 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 18,821.85 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 16,253.05 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 7,826.09 </td><td style="font-weight: bold;text-align: right;border-top: 1px solid black;border-bottom: 1px solid black;background-color: #DBEEF3;;"> 65,000.00 </td></tr><tr ><td style="color: #161120;text-align: center;">15</td><td style="text-align: center;border-top: 1px solid black;;">*** example of how we need to convert the data via a query into the above format… booked revenue broken out by month. This is done by pro-rating based on days in month and length of campaign</td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td><td style="text-align: center;border-top: 1px solid black;;"></td></tr><tr ><td style="color: #161120;text-align: center;">16</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td></tr><tr ><td style="color: #161120;text-align: center;">17</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet1</p><br /><br />
In "Example 2" ws cell E11 the following excel formula exists:
Code:
=IF(E$10="","",$D11*(IF(AND(DATE(YEAR($B11),MONTH($B11),DAY(1))=DATE(YEAR($C11),MONTH($C11),DAY(1)),MONTH(E$10)=MONTH($C11),YEAR(E$10)=YEAR($C11)),1,IF(OR($B11>DATE(YEAR(E$10),MONTH(E$10)+1,0),$C11<E$10),0,IF(AND(YEAR(E$10)=YEAR($C11),MONTH(E$10)=MONTH($C11)),DAY($C11),(DAY(EOMONTH(E$10,0))-DAY(MAX(E$10,$B11)))+1)/($C11-$B11+1)))))
This formula is used to determine if the order start date and end date applies to the given month (header) and if so pro-rate the total cost of the order to the month based on the number of days.
I have build an Access Query that dynamically builds out a table similar to "Example 2" above based on "Example 1" data table, however I need help simplifying my formula noted above... it seems to be too complex, it works in Excel but too complex for Access to handle. Below is the same code for one of my data fields but configured for VB and SQL which is passed to each field in my query:
Code:
1/1/2008: [Total_Net_Revenue]*IIf((Month([Start_Date])=Month([End_Date])) And (Year([Start_Date])=Year([End_Date])),1,IIf(([Start_Date]>DateSerial(Year(#1/1/2008#),Month(#1/1/2008#),0)) Or ([End_Date]<#1/1/2008#),0,IIf((Year(#1/1/2008#)=Year([End_Date])) And (Month(#1/1/2008#)=Month([End_Date])),Day([End_Date]),(Day(DateSerial(Year(#1/1/2008#),Month(#1/1/2008#),0))-Day(IIf(#1/1/2008#>[Start_Date],#1/1/2008#,[Start_Date]))+1)/([End_Date]-[Start_Date]+1))))
Does anyone have any suggestions regarding how to simplify this formula/code or other methods of obtaining my desired results evident in "Example 2"?
Thanks in advance for your help... I've hit a road block LOL