With conn
If .State = 1 Then
.Close
End If
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & strSQL
.Open
End With
With rs
.Open "SELECT Id, IDvalue FROM Table1 ORDER BY Id;", conn, adOpenStatic, adLockOptimistic
if .BOF and .EOF then
N=0 '记录数为0
exit sub
end if
.movefirst
.movelast
N=.recordcount '记录数大于0
End With
'如果你要统计字段IDValue的值
dim i as long
dim allValue as Double '如果是货币,应定义为Currency类型
rs.movefirst
for i=1 to N
allvalue =allvalue + .Fields("IDValue")
rs.movenext
next N