Why RecordCount always return -1?

  • Thread starter Thread starter George
  • Start date Start date
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
 
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
 
Back
Top