Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2004, 06:42 PM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql to return distinct count

I have 1 table (spneeds), that has 3 fields: ClientName, VolunteerName and Disability. I need a count of distinct volunteers that serve several disabilities. After many hours of trying I found out that distinct count doesn't work. Count works by itself and distinct works by itself but they dont work together. So I have 2 queries, the first one takes the distinct volunteers, and the other counts how many.

SELECT DISTINCT [spneeds].[VolunteerName]
FROM spneeds
WHERE ([spneeds].[Disability]='Blind') Or ([spneeds].[Disability]='Deaf') Or ([spneeds].[Disability]='Autistic');

and the second one calls the first:

SELECT Count([VolunteerName]) AS vemotional
FROM [query distinct count];

So I get the correct number.

Question:
How do I get it so that I can put it in another table with all the counts... or put it in a variable, so I can insert it into another table. I tried DoCmd.RunSQL (SQL) but it doesn't return a value, it's only for inserting/updating..

Thanks in advance.

 
Old October 28th, 2004, 10:44 PM
Authorized User
 
Join Date: Oct 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you want the result in a variable, open a recordset on the totals query. If you want the result inserted into a table, use the SELECT from the totals query in an INSERT query:

INSERT INTO MyTable (CountEmotional)
SELECT Count([VolunteerName]) AS vemotional
FROM [query distinct count];



John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
 
Old October 29th, 2004, 06:29 AM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks :D ALOT!
Ugh, now I can go to sleep!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Distinct Jonas Access 2 August 14th, 2006 01:03 PM
count distinct values Chris Cash XSLT 3 June 8th, 2006 04:55 PM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
count distinct nodes alexshiell XSLT 2 January 27th, 2005 11:19 AM
COUNT ON SELECT DISTINCT stmt savoym SQL Language 7 August 28th, 2003 07:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.