EXCEL VBA - recordcount = -1

Joined
May 6, 2010
Messages
4
Reaction score
0
I am having a problem displaying the recordcount for a recordset. I am using ODBC to connect to a local mySQL database. When I create the recordset and have it copied into my excel spreadhseet I have no problems; the data copies successfully into the sheet. However, when I try to get a recordcount it always gives me -1 instead of the number of records in the recordset. I am new to ODBC connections to MySQL so maybe I missed something. Code is below:

Dim localConn As ADODB.Connection
Set localConn = New ADODB.Connection
Dim connString As String

connString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=mydb;" _
& "User=root;Password=passwd;Option=3;"


localConn.Open connString



Dim subentryCount As ADODB.Recordset
Set subentryCount = New ADODB.Recordset


Dim countSQL As String

countSQL = "SELECT * FROM subentry;"


subentryCount.Open countSQL, localConn, adOpenDynamic, adLockReadOnly

Range("A3").CopyFromRecordset subentryCount



MsgBox subentryCount.RecordCount 'This is where I get the error. It always returns -1

subentryCount.Close
Set subentryCount = Nothing

localConn.Close
 
Back
Top