Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Count records in Access

New Here ,
Mar 07, 2007 Mar 07, 2007
I have an access database with a field named color. There are several records containing a color name. I want to list the unique values with the record count of each. Like Red 5, Blue 23, Green 14 etc. How can I accomplish this?

I will be using asp/vbscript. Thanks
TOPICS
Server side applications
202
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 07, 2007 Mar 07, 2007
You can create a recordset for each color like so:

SELECT Count(*) AS Total
FROM colors
WHERE colorName = 'colorName'

Or you could create loops for all the colors to loop through a single recordset to keep count of the colors. Simliar to:

<%
while not rs.eof
dim redCounter
dim blueCounter

if rs.fields.item("colorName") = 'blue' then
blueCounter += 1
elseif rs.fields.item("colorName") = 'red' then
redCounter +=1
end if

loop
%>

That is just off the top of my head, you will need to do some tweaking to get it to work for your application. That should point you in the right direction.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 07, 2007 Mar 07, 2007
LATEST
SELECT COUNT (*) AS TotalRows
FROM tablename
WHERE field = 'red';
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines