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

Access 2010: 'the expression cannot be used in a calculated column'?
ACCESS SubForm: trying to add records
Checking social security numbers and business identity codes in Access 97
MS Access VBA Substitution Cipher Encrypt/Decrypt
How to get SQL from column/query schema in Access
MS Access sub-sub forms
Access 2010 web compatibility error: ACCWeb107019
MS ACCESS: Populate a subform with data from another table
how to read one field from one record
How do you dynamically create controls on a MS Access form?
MS Access date sorting with date/time components combined in one text field
Using Access 2003 VBA, I want to be able to have a report come up on the screen, not print out. But it doesn't work
“invalid use of null” for vba function that returns variant
Refresh combo box in Access 2007 without coding
select top 700 * from objectaer work only in sqlserver 2005 but 2008
All of my reports in MS Access were suddenly deleted

Categories

HOME
testing
arduino-uno
osgi
google-play
cplex
octobercms
electronics
cakephp-2.5
fingerprint
indesign
constraint-programming
ios-charts
upload
primary-key
reveal.js
google-apps-marketplace
zend-framework3
visual-studio-cordova
dynamics-crm-online
normalizr
amazonsellercentral
mmap
autosys
status
react-css-modules
internet-explorer-9
elasticsearch-net
saas
tasklet
contact-form
android-ble
appfabric
main
xcode-extension
code-search-engine
sharefile
ssjs
angularjs-factory
ensembles
gulp-sourcemaps
heightmap
gpx
.net-4.6.2
outlook-2013
appcompat
network-flow
alphabet
domain-model
darcs
tactic
lift-json
dtexec
capacity
mcafee
minimization
multi-level
fputcsv
ubuntu-10.04
essence
cloudbees
jfugue
javax.sound.midi
reactive-banana
metaclass
jmeter-maven-plugin
fouc
tableau-online
processmodel
proj4js
dereference
notify
bigbluebutton
fscommand
jscript.net
codeigniter-url
dealloc
runtime.exec
eclipse-memory-analyzer
android-screen-support
robotics-studio
selected
simba
cisco-jtapi
dice
frameset
venn-diagram
appconkit
regsvr32
removeclass
nsdatecomponents
zpt
rfc1123
yetanotherforum
table-footer
site.master
sortable-tables
suppress
web-architecture
backcolor
ti-dsp
adrotator
yagni
spec#
windows-live-messenger
3gp
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