Why RecordCount always return -1?

G

George

Hi, Why RecordCount always return -1? How to set the recordset to return
correct recordcount?
(working enviroment: Access 2002 on XP home box)

Following is the code for your referenc:

Dim cnn As Connection
Dim rsStudent As ADODB.Recordset
Dim strStudentSQL As String

Set cnn = CurrentProject.Connection
Set rsStudent = New ADODB.Recordset
strStudentSQL = "Select * from students"
rsStudent.ActiveConnection = cnn
rsStudent.Open strSQL, , adOpenDynamic, adLockOptimisticL
MsgBox rsStudent.RecordCount
 
G

Gerald Stanley

Since you are taking the connection string as
CurrentProject.Connection, the location of the recordset is
defaulting to adUseServer. You need to change this to
adUseClient. So try inserting the following line after
rsStudent.ActiveConnection = cnn
rsStudent.ActiveConnection.CursorLocation = adUseClient

Hope This Helps
Gerald Stanley MCSD
 
Top