473,378 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Count *

675 512MB
I have read a million posts about how to find the number of records in a query. The statement "SELECT COUNT(*) FROM table" is very nice, but how do I "know" the result.

I need a statement such as: i = "SELECT COUNT(*) FROM table", so i is the number of items in table. I can write the appropriate WHERE clause.

Currently I am using a hidden listbox, where listbox.rowsource="SELECT ..." and then i = listbox.listcount. Is there a more efficient way?

OldBirdman
Dec 28 '07 #1
4 1837
jaxjagfan
254 Expert 100+
I have read a million posts about how to find the number of records in a query. The statement "SELECT COUNT(*) FROM table" is very nice, but how do I "know" the result.

I need a statement such as: i = "SELECT COUNT(*) FROM table", so i is the number of items in table. I can write the appropriate WHERE clause.

Currently I am using a hidden listbox, where listbox.rowsource="SELECT ..." and then i = listbox.listcount. Is there a more efficient way?

OldBirdman
Try using Dsum function. Exclude the criteria if you want a count of all records.

i = DSum([yourfield],"yourtablename").
Dec 28 '07 #2
OldBirdman
675 512MB
DSUM and similar functions require a "table name" or "query name". I need to knoiw how many rows for either a query built "on-the-fly", or for an underlying dataset for a form or control.

If strSQL = "SELECT * FROM tableA WHERE [Value]>100000;", then I want to assign to i the number of records that are selected.

If I have a listbox lbxA, then if lbxA.RowSource=strSQL, I can then assign i by i=lbxA.ListCount. Simple, but klutzy as I have to have a hidden control lbxA on my form. But it does work. I should be able to do this by the COUNT function, without the hidden control. How?

OldBirdman
Dec 30 '07 #3
missinglinq
3,532 Expert 2GB
Not only does DSUM require a "table name" or "query name," but it, amazingly, does exactly what its name suggests, totals the values in a given field of said table/query! Unless the value in each instance of this field was 1 it wouldn’t be much use in determining the number of records. Perhaps jaxjagfan was thinking of Dcount().

Perhaps you could incorporate your code with the example given by ADezii in his Testing for an Empty Recordset. Towards the end he addresses the issue of counting records.

Linq ;0)>
Dec 30 '07 #4
OldBirdman
675 512MB
I noticed that DSUM wasn't quite what I wanted. I am slow to respond, because an answer, although not exactly what I want may contain the answer that I do want. In this case, I first considered doing a SELECT where there was an additional field, lets just say "1 as ZZZ". Now I can do a DSUM, as each record has a field with a value of "1". Of course, I also found DCOUNT.

Further investigation, starting from DSUM found ii = rst.RecordCount, which was a nice, generic solution to many counting issues.

My thanks to jaxjagfan for pointing me in this direction, and thank you missinglinq for monitoring the post, and being sure that I understood.

OldBirdman
Jan 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
6
by: Geetha | last post by:
I searched in the Oracle documents what count (1) meant and I could not find an answer. Can some one explain what Oracle does internally when use count (1) VS count (*). Thank you very much in...
1
by: JD | last post by:
Hi guys I'm trying to write a program that counts the occurrences of HTML tags in a text file. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h> ...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
23
by: Gary Wessle | last post by:
Hi I have a vector<charwhich looks like this (a d d d a d s g e d d d d d k) I need to get the biggest count of consecutive 'd'. 5 in this example I am toying with this method but not sure if...
1
by: heckstein | last post by:
I am working in Access 2002 and trying to create a report from our company's learming management system. I am not a DBA and most of my SQL knowledge has been self taught through trial and error. I...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
3
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php,...
7
by: Chris | last post by:
I am trying to increase/decrease the value of $_SESSION by 1 after clicking on a link e.g index.php?gotoWk=nxtWk and index.php? gotoWk=lstWk. I'm sure you will get the drift if you look at the code...
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.