Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 28th, 2004, 06:42 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
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.

Reply With Quote
  #2 (permalink)  
Old October 28th, 2004, 10:44 PM
Authorized User
 
Join Date: Oct 2004
Location: Austin, TX, USA.
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"
Reply With Quote
  #3 (permalink)  
Old October 29th, 2004, 06:29 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.