LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Why am I getting a recordcount of -1

I've been trying to count the number of records in a query that I'm
pulling back to Excel from Access. The query returns about 13K
records, but my recordcount keeps coming back as -1.

What am I doing wrong here?

Thanks

Public Sub SelectFromAccess()

Dim rsData As ADODB.Recordset
Dim sPath As String
Dim sConnect As String
Dim sSQL As String

' Clear the destination worksheet.
Sheet1.UsedRange.Clear

' Get the database path (same as this workbook).
sPath = ThisWorkbook.Path
If Right$(sPath, 1) < "\" Then sPath = sPath & "\"

' Create the connection string.
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sPath & "TestExcelData.mdb;"

' Build the SQL query.
sSQL = "SELECT [CM Data Store].* FROM [CM Data Store];"

' Retrieve the data using ADO.
Set rsData = New ADODB.Recordset
rsData.Open sSQL, sConnect, _
adOpenForwardOnly, adLockReadOnly, adCmdText

If Not rsData.EOF Then
Sheet1.Range("A2").CopyFromRecordset rsData
Else
MsgBox "No data located.", vbCritical, "Error!"
End If

'Get the record count
MsgBox rsData.RecordCount

rsData.Close
Set rsData = Nothing

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RecordCount not working T. S. Excel Programming 1 February 27th 07 11:34 PM
Reg: Incorrect RecordCount when opened a Excel sheet in ADO Recordset dev[_5_] Excel Programming 4 June 23rd 05 09:48 AM
Recordset.Recordcount Returns -1! Sauron[_24_] Excel Programming 1 June 28th 04 09:11 AM
RecordCount problem Terence Excel Programming 1 August 11th 03 09:10 AM


All times are GMT +1. The time now is 08:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"