ms-access


Microsoft Access 2010 VB Script and Query


I am doing a report in MS Access, and I want to use VB Script to filter some of my data, but I have never used it before. I have a table (query) that I would like to return the customers who have made ALL of their orders online. I’ve tried different combination, where I set if ID is same to add the price for ONLY customers who have made all of their orders online. I am failing miserably. Any help would be greatly appreciated. I’ve created a replica of the table in JSFiddle. For instance, when it is done the report will only have the following customers: John Smith, Irene François, William Gedeon, and Joshua Gonzalez, since they are the customers who have made all of their orders online for the month of March. Please see the link below for a better understand of the data. Thank you very much.
<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 Link: "http://jsfiddle.net/xqmDE/29/"
Best,
ZDM
You don't need VB script to do this (although you can use it if you want - see below).
NOTE: I have presumed a table name of 'Orders' and fields of 'CustomerID' and 'SourceOfOrder'.
Apply the following in the 'Filter' property of the report, and make sure both the 'Filter On Load' and 'Allow Filters' properties are set to 'Yes'
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'
If you want to do it in VBA put the following:
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

Related Links

How to extract images from Access CommandButton?
Finding Autonumber ID for new record in Access 2007
Does MS Access Runtime 2010 works well on system with previous version of Access/Office installed?
“Too many indexes on table” error when creating relationships in Microsoft Access 2010
Display related fields from another table on a Microsoft Access form
How to pass values from client side html to server side in classic asp or vbscript?
Access Report ignores DISTINCROW in query
checking whether field in table has space or comma - MS-Access
Forms and Subforms in Access 2003
EasyPHP connecting to MS Access
Access 2010 Runtime question
Access Input textbox on Data Access page with only select enabled to allow filter by searchs
Microsoft Access Query through VBA gets repeated?
What sort of functionality can I expect from exporting a Microsoft Access 2007 Database to a WSS 3.0 site?
query muliple fields with multiple values
Force OpenCurrentDatabase to use Access 2003

Categories

HOME
vim
hook
cmd
yarn
electronics
cakephp-2.5
jgroups
upload
pheatmap
adfs
virtualization
facebook-messenger-bot
here-api
nano-server
quicklook
visual-studio-2005
windows-server-2012
workload-scheduler
clojurescript
saxon
jsdoc
textfield
swingx
zapier
kryo
jquery-ajaxq
apache-commons-io
buck
compatibility
c++-amp
nat
fabric8
google-rich-snippets
ecto
preg-match-all
airconsole
column-family
code-contracts
perlin-noise
bower-install
vxworks
bitbucket-pipelines
gesture
neuroscience
android-browser
abstract-class
opshub
gzipstream
turbogears
vao
logfiles
domain-model
rdfs
idisposable
nsarray
windows-iot-core-10
spring-cache
minimization
nxt
mathematica-frontend
independentsoft
wapiti
netmq
execute
qdialog
content-length
event-bubbling
sailfish-os
graph-api-explorer
skos
jsapi
kineticjs
xc16
navigationservice
valueconverter
expected-exception
dealloc
imdbpy
clipper
quickdialog
onsubmit
qtkit
jquery-ui-layout
spring-portlet-mvc
asyncfileupload
joyent
tomcat-valve
telerik-scheduler
jquery-ui-droppable
aquaticprime
caching-application-block

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App