Public Function CountRecordsFiltered(strWhere) As Integer
Dim rsResult As ADODB.Recordset
strWhere = Replace(strWhere, "#", "'")
If strWhere <> "" Then
strQuery = "SELECT count(*) as Total from Customers WHERE " & strWhere
Else
strQuery = "SELECT count(*) as Total from Customers"
End If
Set rsResult = CurrentProject.Connection.Execute(strQuery)
I don' think the recordsets of ADP's are DAO. I think they are ADO. Not all ADO recordsets supports RecordCount, but the following, which is doing some testing for it, might work, using the RecordsetClone.
I don't use ADP's much, so I can't be sure I've trapped all relevant possibilities.
[tt]dim rs as adodb.recordset
set rs = me.recordsetclone ' or recordset.clone
dim lngCount as long
if not rs.eof then
if rs.supports(adbookmark) and rs.supports(adapproxposition) then
me!txtCount.value = rs.recordcount
else
do while not rs.eof
lngCount = lngCount +1
rs.movenext
loop
me!txtCount.value = lngCount
end if
else
me!txtCount.value = 0
end if[/tt]
- note - typed not tested
But, I'm inclined to believe jsnunez solution is one of the more reliable ways of getting correct recordcount with ADO, if "=Count(IdField)" as controlsource isn't an option (though it shouldn't be necessary to perform .movelast/.movefirst).
However, substitute "ADODB.Recordset" for "DAO.Recordset"
and my solution will work (with way less "work") and will be MUCH faster.
Also, you might not need to do a .movelast (see the part about testing for support of bookmarks and approxposition) I wasn't aware of those properties being available to see if the recordcount is "available" without going to the last record.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.