Solved

How do I count records from a Statement, however if the same record is multiple, then count them together

Posted on 2015-02-06
14
75 Views
Last Modified: 2015-02-08
want to show a count of some records

however some records values will be the same, so I want these counted as multiple.

eg
SYD 1
MEL 2
DPS 4

not
SYD
MEL
DPS
MEL
DPS
DPS
DPS

is there a way of showing this?
0
Comment
Question by:Graeme
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 300 total points
ID: 40595082
using a query

select [FieldName], Count([FieldName])
from tableName
group by  [FieldName]
0
 

Author Comment

by:Graeme
ID: 40595090
Thanks for that I have correct my query so that it works

Set KPIsDest=oConn.Execute("SELECT enq_dest,COUNT(enq_dest) FROM enq WHERE enq_date BETWEEN #"&SOMonth&"# AND #"&EOMonth&"# GROUP BY enq_dest")                                          

How do I show the count of each record?

eg
SYD 1
MEL 2
DPS 4
0
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40595092
You can also try:
select distinct  [FieldName], Count([FieldName]) from tableName
group by  [FieldName]
0
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40595095
Or
select count(distinct FieldName), FieldName
from tableName
group by  FieldName
0
 
LVL 30

Expert Comment

by:hnasr
ID: 40595097
Since this is just a simple function in access, I might suggest using the query wizard to find Duplicates.
Then you may modify the query by removing the >1 criteria, either in design view or sql view.

This helps in improving your access programming. You may modify the query to get other functions, like Sum or Count, by replqacing Count or adding to it.
0
 

Author Comment

by:Graeme
ID: 40595159
Hey all, just need the code to show the records and how many of each
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40595214
where do you want to show the records?
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:Graeme
ID: 40595216
As a list

eg
SYD 1
MEL 2
DPS 4

is this what you meant?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40595225
As a list , where ?
0
 

Author Comment

by:Graeme
ID: 40595244
Sorry I do not get what you mean by 'where' ?

Here is the code:

<%
Set KPIsDest=oConn.Execute("SELECT enq_dest,COUNT(enq_dest) FROM enq WHERE enq_date BETWEEN #"&SOMonth&"# AND #"&EOMonth&"# GROUP BY enq_dest")							
%>
	<tr>
		<td colspan=8 align=center>Destinations</td>
		<td colspan=2>&nbsp;</td>
	</tr>
	<tr>
		<td height=20 width=20% colspan=2>0%</td>
		<td height=20 width=20% colspan=2>25%</td>
		<td height=20 width=20% colspan=2>50%</td>
		<td height=20 width=20% colspan=2>75%</td>
		<td height=20 width=20% colspan=2>100%</td>
	</tr>
<%
	Do While Not KPIsDest.eof
%>
	<tr>
		<td colspan=8>
			<table width=100% border=0>
				<tr>
					<td height=20 bgcolor=black width=<%=FormatNumber(((!!!!!!!/EnqCount)*100),2)%>%></td>
					<td height=20>&nbsp;</td>
				 </tr>
			</table>
		</td>
		<td><%=KPIsDest("enq_dest")%></td>
		<td><%=FormatNumber(((!!!!!!!!!/EnqCount)*100),2)%>% Destinations Strikerate</td>
	</tr>
<%
	KPIsDest.MoveNext 
		LOOP
	KPIsDest.Close
%>

Open in new window


where i have the !!!!! is where i need the sum count total of the destinations
0
 
LVL 84
ID: 40595489
So you want to show this on a web page. That's what Rey was asking. We don't know what programming environment you're using, so asking us "how to  show a list" doesn't make much sense to us.

You'd have to loop through the recordset and add rows to your table:

Do Until kpIsDest.EOF
<tr>
            <td colspan=8>
                  <table width=100% border=0>
                        <tr>
                              <td height=20 bgcolor=black width=<%=FormatNumber(((kpIsDest("YourNumberColumn")/EnqCount)*100),2)%>%></td>
                              <td height=20>&nbsp;</td>
                         </tr>
                  </table>
            </td>
            <td><%=KPIsDest("enq_dest")%></td>
            <td><%=FormatNumber(((kpIsDest("YourNumberColumn")/EnqCount)*100),2)%>% Destinations Strikerate</td>
      </tr>
Loop
0
 

Author Comment

by:Graeme
ID: 40596718
hello and thanks for clarifying...

KPIsDest("YourNumberColumn") being what ?

what do you need from me to figure out which column i am looking for?
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 200 total points
ID: 40596749
YourNumbercolumn is the column from your SQL statement which would contain the value you want to show. It would be either "eng_dest", or the COUNT(eng_dest) column. Since I assume it's the COUNT column, you might change the SELECT statement to this:

SELECT enq_dest, COUNT(enq_dest) AS DestCount FROM enq WHERE enq_date etc etc

Then refer to it like this:

kpIsDest("DestCount")
0
 

Author Closing Comment

by:Graeme
ID: 40597492
Cheers all for your help!

works a treat!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now