[AccessD] How to - get a count for a condition

Mackin, Christopher CMackin at Quiznos.com
Thu May 13 09:55:44 CDT 2004


If you already have the query that gets the records you want, just use
something like:

Public Function GetRecCount() As Long
Dim rst as ADODB.Recordset

strSQL = "SELECT COUNT(*) FROM YourQueryName"
Set rst = New ADODB.Recordset

rst.Open strSQL, CurrentProject.Connection, adStatic

GetRecCount = rst(0)

rst.Close
Set rst = nothing

End Function

You could of course pass the query name to the function and build the SQL
string dynamically to make it a lot more globally useful, but this covers
the basic concept.

Chris Mackin





----- Original Message ----- 
From: "John Clark" <John.Clark at niagaracounty.com>
To: <accessd at databaseadvisors.com>
Sent: Thursday, May 13, 2004 10:11 AM
Subject: [AccessD] How to - get a count for a condition


> I thought this would be simpler, but...I need to get a count for records
> logged in a given time period, and I seem to be at a loss. Basically, I
> have a field called 'datLoginDate' and I want to find all records
> 'logged' during a period, which I will get from a 'BegDate' and an
> 'EndDate' on the form.
>
> I first thought they wanted a list of the records, so I have a query
> already that finds these records. And, I know from running the query,
> how many records exist. But, how do I just get the number?
>
> This program is A97, but I am moving it over to A2K soon, so a solution
> for both would be great.
>
> Thanks!
>
> John W Clark
> -- 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list