Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Num Records in Access table

Status
Not open for further replies.

SlakeB

MIS
Jun 15, 2005
40
US
I'm trying to count the number of records in an error log table and display the result to the screen.

Code:
Dim sqlCount, rsCount
set rsCount = CreateObject("ADODB.Recordset")
rsCount.open "tblErrorLog",objConn1
sqlCount="SELECT COUNT(*) FROM tblErrorLog"
set rsCount= objConn1.execute(sqlCount)
wscript.echo rsCount("TotCount")

Can anyone see the error?
 
What error are you getting.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I think I answered my own question. This works:

Code:
Set rsCount = CreateObject("ADODB.Recordset")
rsCount.open "tblErrorLog",objConn1

Dim intErrorCount
intErrorCount = 0
Do While Not rsCount.EOF
	intErrorCount = intErrorCount + 1
	rsCount.moveNext
Loop

wscript.echo intErrorCount
 
And to reply to your first post:
either change this:
sqlCount="SELECT COUNT(*) FROM tblErrorLog"
By this:
sqlCount="SELECT COUNT(*) AS TotCount FROM tblErrorLog"

Or this:
wscript.echo rsCount("TotCount")
By this:
wscript.echo rsCount(0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top