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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top