我在MS Access中做报告,我想使用VB脚本来过滤我的一些数据,但我以前从未使用过它。我有一个表(查询),我想返回已经在线完成所有订单的客户。我尝试了不同的组合,我设置了ID是否相同,只为在线完成所有订单的客户增加价格。我悲惨地失败了。任何帮助将不胜感激。我在JSFiddle中创建了表的副本。例如,当报告完成时,报告将只有以下客户:John Smith,IreneFrançois,William Gedeon和Joshua Gonzalez,因为他们是在3月份在线完成所有订单的客户。请参阅以下链接以更好地了解数据。非常感谢你。
<table border="1">
<tr>
<th width="120">Month/Year</th>
<th width="120">Customer ID</th>
<th width="120">Last Name</th>
<th width="120">First Name</th>
<th width="120">In/Out of State</th>
<th width="120">Customer Type</th>
<th width="120">Product Name</th>
<th width="120">Source of Order</th>
<th width="120">Price</th>
<th width="120">Monthly Total</th>
</tr>
<tr>
<td>March/2013</td>
<td>000357321</td>
<td>John</td>
<td>Smith</td>
<td>Resident</td>
<td>VIP</td>
<td>Natural Olive Oil</td>
<td>Online</td>
<td>$3</td>
<td>$7</td>
</tr>
<tr>
<td>March/2013</td>
<td>000357321</td>
<td>John</td>
<td>Smith</td>
<td>Resident</td>
<td>VIP</td>
<td>Cream of Coconut</td>
<td>Online</td>
<td>$4</td>
<td>$7</td>
</tr>
<tr>
<td>March/2013</td>
<td>000568354</td>
<td>Purkiss</td>
<td>Andre</td>
<td>Non-Resident</td>
<td>Regular</td>
<td>Pink Candy</td>
<td>In-Store</td>
<td>$7</td>
<td>$17</td>
</tr>
<tr>
<td>March/2013</td>
<td>000568354</td>
<td>Purkiss</td>
<td>Andre</td>
<td>Non-Resident</td>
<td>Regular</td>
<td>Organic Pasta</td>
<td>Online</td>
<td>$4</td>
<td>$17</td>
</tr>
<tr>
<td>March/2013</td>
<td>000568354</td>
<td>Purkiss</td>
<td>Andre</td>
<td>Non-Resident</td>
<td>Regular</td>
<td>Challah Bread</td>
<td>Phone Order</td>
<td>$6</td>
<td>$17</td>
</tr>
<tr>
<td>March/2013</td>
<td>025999248</td>
<td>François</td>
<td>Irene</td>
<td>Resident</td>
<td>Regular</td>
<td>Bottle Opener</td>
<td>Online</td>
<td>$8</td>
<td>$21</td>
</tr>
<tr>
<td>March/2013</td>
<td>025999248</td>
<td>François</td>
<td>Irene</td>
<td>Resident</td>
<td>Regular</td>
<td>Key Chain</td>
<td>Online</td>
<td>$4</td>
<td>$21</td>
</tr>
<tr>
<td>March/2013</td>
<td>025999248</td>
<td>François</td>
<td>Irenee</td>
<td>Resident</td>
<td>Regular</td>
<td>Printing Paper</td>
<td>Online</td>
<td>$5</td>
<td>$21</td>
</tr>
<tr>
<td>March/2013</td>
<td>025999248</td>
<td>François</td>
<td>Irene</td>
<td>Resident</td>
<td>Regular</td>
<td>Cho. Chip Cookies</td>
<td>Online</td>
<td>$4</td>
<td>$21</td>
</tr>
<tr>
<td>March/2013</td>
<td>091357456</td>
<td>Abramovitch</td>
<td>Tayron</td>
<td>Resident</td>
<td>VIP</td>
<td>Banana</td>
<td>Phone Order</td>
<td>$3</td>
<td>$10</td>
</tr>
<tr>
<td>March/2013</td>
<td>091357456</td>
<td>Abramovitch</td>
<td>Tayron</td>
<td>Resident</td>
<td>VIP</td>
<td>Fried Onions</td>
<td>Online</td>
<td>$7</td>
<td>$10</td>
</tr>
<tr>
<td>March/2013</td>
<td>022864295</td>
<td>Hatchner</td>
<td>Emily</td>
<td>Non-Resident</td>
<td>VIP</td>
<td>Vodka Sauce</td>
<td>In-Store</td>
<td>$5</td>
<td>$34</td>
</tr>
<tr>
<td>March/2013</td>
<td>022864295</td>
<td>Hatchner</td>
<td>Emily</td>
<td>Non-Resident</td>
<td>VIP</td>
<td>Old Cheese</td>
<td>Online</td>
<td>$8</td>
<td>$34</td>
</tr>
<tr>
<td>March/2013</td>
<td>022864295</td>
<td>Hatchner</td>
<td>Emily</td>
<td>Non-Resident</td>
<td>VIP</td>
<td>Tomatoes</td>
<td>Phone Order</td>
<td>$4</td>
<td>$34</td>
</tr>
<tr>
<td>March/2013</td>
<td>022864295</td>
<td>Hatchner</td>
<td>Emily</td>
<td>Non-Resident</td>
<td>VIP</td>
<td>Frying Pan</td>
<td>Online</td>
<td>$17</td>
<td>$34</td>
</tr>
<tr>
<td>March/2013</td>
<td>092456753</td>
<td>Gedeon</td>
<td>William</td>
<td>Non-Resident</td>
<td>Regular</td>
<td>USB Drive</td>
<td>Online</td>
<td>$2</td>
<td>$13</td>
</tr>
<tr>
<td>March/2013</td>
<td>092456753</td>
<td>Gedeon</td>
<td>Williame</td>
<td>Non-Resident</td>
<td>Regular</td>
<td>Cordless Keyboard</td>
<td>Online</td>
<td>$4</td>
<td>$13</td>
</tr>
<tr>
<td>March/2013</td>
<td>092456753</td>
<td>Gedeon</td>
<td>William</td>
<td>Non-Resident</td>
<td>Regular</td>
<td>MacBook Charger</td>
<td>Online</td>
<td>$7</td>
<td>$13</td>
</tr>
<tr>
<td>March/2013</td>
<td>000320680</td>
<td>Baltar</td>
<td>D'Anna</td>
<td>Non-Resident</td>
<td>Regular</td>
<td>Pineapple</td>
<td>In-Store</td>
<td>$3</td>
<td>$5</td>
</tr>
<tr>
<td>March/2013</td>
<td>000320680</td>
<td>Baltar</td>
<td>D'Anna</td>
<td>Non-Resident</td>
<td>Regular</td>
<td>Fresh Fish</td>
<td>Online</td>
<td>$2</td>
<td>$5</td>
</tr>
<tr>
<td>March/2013</td>
<td>04400250</td>
<td>Gonzalez</td>
<td>Joshua</td>
<td>Resident</td>
<td>VIP</td>
<td>NotePad</td>
<td>Online</td>
<td>$5</td>
<td>$19</td>
</tr>
<tr>
<td>March/2013</td>
<td>04400250</td>
<td>Gonzalez</td>
<td>Joshua</td>
<td>Resident</td>
<td>VIP</td>
<td>Plastic Binder</td>
<td>Online</td>
<td>$4</td>
<td>$19</td>
</tr>
<tr>
<td>March/2013</td>
<td>04400250</td>
<td>Gonzalez</td>
<td>Joshua</td>
<td>Resident</td>
<td>VIP</td>
<td>Box of Pencils</td>
<td>Online</td>
<td>$4</td>
<td>$19</td>
</tr>
<tr>
<td>March/2013</td>
<td>04400250</td>
<td>Gonzalez</td>
<td>Joshua</td>
<td>Resident</td>
<td>VIP</td>
<td>Au. Picture Frame</td>
<td>Online</td>
<td>$6</td>
<td>$19</td>
</tr>
</table>
JSFiddle链接:“http://jsfiddle.net/xqmDE/29/”
最佳,
ZDM
答案 0 :(得分:0)
您不需要VB脚本来执行此操作(尽管您可以根据需要使用它 - 请参阅下文)。
注意:我假设一个表名为'Orders',字段为'CustomerID'和'SourceOfOrder'。
在报告的“过滤器”属性中应用以下内容,并确保“加载时过滤”和“允许过滤器”属性都设置为“是”
CustomerID IN (
(SELECT CustomerID FROM
(SELECT CustomerID, SourceOfOrder
FROM Orders
GROUP BY CustomerID, SourceOfOrder
) orders_grouped
GROUP BY CustomerID
HAVING Count(SourceOfOrder) = 1)
) AND SourceOfOrder = 'Online'
如果你想在VBA中这样做,请输入以下内容:
Private Sub Report_Load()
Reports!Orders.Filter = "CustomerID IN ((SELECT CustomerID FROM (SELECT CustomerID, SourceOfOrder FROM Orders GROUP BY CustomerID, SourceOfOrder) orders_grouped GROUP BY CustomerID HAVING Count(SourceOfOrder) = 1)) AND SourceOfOrder = 'Online'"
Reports!Orders.FilterOn = True
End Sub