ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   count number of sql query result (https://www.excelbanter.com/excel-programming/391996-count-number-sql-query-result.html)

dan

count number of sql query result
 
Is there a property that count the result of an SQL query.
I could find one that count the number of fields, but not the number of
results.

Is there another way to find out if an SQL return any result or no result
are returned.

Thanks

Dan


Keith74

count number of sql query result
 

Far as i know you have to run a loop for the number of records

i.e.

myrecordset.movefirst

do until myrecordset.eof = true
count = count + 1
myrecordset.movenext
loop

myrecordset.movefirst

The way i find out if i have an empty recordset is

if myrecordset.bof = true and myrecordset.eof = true then
your code here
end if


hth

keith


GysdeJongh

count number of sql query result
 
"Dan" wrote in message
...
Is there a property that count the result of an SQL query.
I could find one that count the number of fields, but not the number of
results.

Is there another way to find out if an SQL return any result or no result
are returned.


Dim strSQL As String
Dim rcsCheck As New ADODB.Recordset
Dim intNumberOfRecords As Integer
'
strSQL = "Your Query"
rcsCheck.Open strSQL, "Provider=MSDASQL;DSN=YourDSN", adOpenStatic,
adLockOptimistic
intNumberOfRecords = rcsCheck.RecordCount

I tried a few things but this only seems to work for adOpenStatic,
adLockOptimistic
hth
Gys




All times are GMT +1. The time now is 05:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com