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.
Printable View
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.
Code:rcd.MoveLast
numberOfREcords = rcd.recordcount
I believe it is only reliable if the cursor is set to client... adUseClient, if you use the RecordCount property.
Hi, thanks for the reply,
may i ask that what is the meaning of adClient?
could you elaborate on that?
thanks a lot.
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.
Like many things with programming it is a pearl of wisdom you once heard and forget where it came from.VB Code:
Dim cn as ADODB.Connection set cn = new ADODB.Connection cn.CursorLocation=adUseClient
You can always execute a sql statement to count the records too.
SELECT Count(*) As TotalRecs FROM Table1;