PDA

Click to See Complete Forum and Search --> : Finding the Number of Rows


spoonjy
Dec 19th, 2005, 04:33 AM
Hi, May i know after i open my database, what is the code for finding the number of rows in my table?

Set MyDatabase = DBEngine.OpenDatabase("C:\temp.mdb", True)

Set rcd = MyDatabase.OpenRecordset("tbl_Main")
rcd.MoveFirst

thanks in anticipation.

Br1an_g
Dec 19th, 2005, 06:30 AM
rcd.MoveLast
numberOfREcords = rcd.recordcount

BillBoeBaggins
Dec 19th, 2005, 04:57 PM
I believe it is only reliable if the cursor is set to client... adUseClient, if you use the RecordCount property.

spoonjy
Dec 19th, 2005, 07:08 PM
Hi, thanks for the reply,
may i ask that what is the meaning of adClient?
could you elaborate on that?
thanks a lot.

BillBoeBaggins
Dec 19th, 2005, 07:15 PM
EDIT: This is only for ADO, if your using DAO then none of my posts apply. And just use RecordCount normally as the other guy says.

It is a constant for ADO, maybe DAO as well not sure about DAO. But anyways, when your setting up your connection you indicate that you want the "cursor" to reside locally on your machine by setting the property. I actually forgot most of the reasons behind using a client side cursor.

Dim cn as ADODB.Connection
set cn = new ADODB.Connection
cn.CursorLocation=adUseClient

Like many things with programming it is a pearl of wisdom you once heard and forget where it came from.

RobDog888
Dec 19th, 2005, 08:36 PM
You can always execute a sql statement to count the records too.

SELECT Count(*) As TotalRecs FROM Table1;