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

SQL Query to MS SQL - Parameter Value
Complex fill in the blanks query in MS Access 2010
Compile Error: User Type Not Defined - MS Access
MSAccess - Requery a Subform After Insert?
MS Access 2016 won't open an .accdb file because it 'was created in a previous version'. Is there a fix?
Export data from Access 2010 to Excel 2013
Access SQL query to match column data with row criteria and fetch score
Disabled Mode, Microsoft Access 2016
JavaFX : where to put portable database file for application
Importing Excel Data into Access Using Index - How to Prevent Popup Message
Include Microsoft Office Access database engine 2007 to installer with InstallShield Limited Edition
Create single report with multiple record data?
What do I gain from specifying relationships in my database?
Microsoft Access VBA: Button to Filter Report
Trying to pull data from text boxes on a form into a query and out to a table?
How do I find DDE connections and update to OLE connections in Access?

Categories

HOME
pandas
xamarin
testng
openmp
mediawiki
plot
include
relay
sqlite-net-extensions
podio
autotools
maude-system
windows-10-universal
vb.net-2010
hex-editors
hapi
decomposition
alpine
nas
csrf-protection
restful-authentication
centos6.5
dynamic-featured-image
fopen
assistant
c++-amp
unboundid
madlib
microsoft-chart-controls
key-value-observing
twilio-api
karaf
grails-3.1
pim
perlin-noise
repo
hexo
restlet
scaffold
vapor
gzipstream
reportingservices-2005
estimote
netcdf4
galleria
jsch
fault
dandelion
alphabet
typescript1.8
togetherjs
drupal-6
carrot
csound
nodebb
libusb-win32
typed-lambda-calculus
python-cryptography
gcsfuse
firebaseui
angstrom-linux
qgraphicsview
bgp
pickadate
php-internals
phpcas
natvis
maven-tomcat-plugin
xna-4.0
msys
teamcity-8.0
tmuxinator
fouc
iis-arr
coveralls
ibaction
cdt
winddk
preferences
zend-route
aapt
dml
kgdb
mysqltuner
oam
aqtime
sitemesh
listings
seed
hamiltonian-cycle
word-processor
errai
ticoredatasync
netbeans-6.9
subscript
vdsp
tomcat-valve
xmemcached
javax.script
radcombobox
simpletest
premature-optimization
project-hosting
scripting-languages
windows-live-messenger
document-conversion

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