Hi,
The following code returns a recordcount of -1 for a spreadsheet that contains 198 rows. the version of XL is 2000. What is wrong? :-
the dlgUpload is a commondialog control.
Public Excel_Connection As ADODB.Connection
Public Excel_RecordSet As ADODB.RecordSet
Public Excel_SQL As String
Private Sub Form_Load()
Dim strFolderPath As String
On Error GoTo ErrHandler
With dlgUpload
.DefaultExt = ".xls"
.FilterIndex = 2
.DialogTitle = "Please select XLS file"
.Filter = "XL Spreadsheet (*.xls)|*.xls"
.ShowOpen
End With
strFolderPath = dlgUpload.FileName
Set Excel_Connection = New ADODB.Connection
Set Excel_RecordSet = New ADODB.RecordSet
With Excel_Connection
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Extended Properties") = "Excel 8.0;IMEX=1;HDR=YES"
.Open strFolderPath
End With
With Excel_RecordSet
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
End With
Excel_SQL = "select * FROM [Sheet 1$]"
Set Excel_RecordSet = Excel_Connection.Execute(Excel_SQL)
MsgBox Excel_RecordSet.RecordCount
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
The following code returns a recordcount of -1 for a spreadsheet that contains 198 rows. the version of XL is 2000. What is wrong? :-
the dlgUpload is a commondialog control.
Public Excel_Connection As ADODB.Connection
Public Excel_RecordSet As ADODB.RecordSet
Public Excel_SQL As String
Private Sub Form_Load()
Dim strFolderPath As String
On Error GoTo ErrHandler
With dlgUpload
.DefaultExt = ".xls"
.FilterIndex = 2
.DialogTitle = "Please select XLS file"
.Filter = "XL Spreadsheet (*.xls)|*.xls"
.ShowOpen
End With
strFolderPath = dlgUpload.FileName
Set Excel_Connection = New ADODB.Connection
Set Excel_RecordSet = New ADODB.RecordSet
With Excel_Connection
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Extended Properties") = "Excel 8.0;IMEX=1;HDR=YES"
.Open strFolderPath
End With
With Excel_RecordSet
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
End With
Excel_SQL = "select * FROM [Sheet 1$]"
Set Excel_RecordSet = Excel_Connection.Execute(Excel_SQL)
MsgBox Excel_RecordSet.RecordCount
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub