T
Todd Huttenstine
Below code gives me the error: Item cannot be found in the
collection corresponding to the requested name or ordinal.
Can anyone tell me why. I get this error near the end of
the code on line "oRS(1).Value = 8"
'Using OLE DB Provider for Jet:
Dim oConn As ADODB.Connection
Dim oCmd As ADODB.Command
Dim oRS As ADODB.Recordset
' Open a connection to the Excel spreadsheet
Set oConn = New ADODB.Connection
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\QTD\Sales.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
' Create a command object and set its ActiveConnection
Set oCmd = New ADODB.Command
oCmd.ActiveConnection = oConn
' This SQL statement selects a cell range in the "Expenses"
' worksheet
oCmd.CommandText = "SELECT * from `Expenses$A2:C4`"
' This SQL statement selects a named cell range
' defined in the workbook
oCmd.CommandText = "SELECT * from `Range1`"
' Open a recordset containing the worksheet data.
Set oRS = New ADODB.Recordset
oRS.Open oCmd, , adOpenKeyset, adLockOptimistic
Debug.Print oRS.RecordCount
' Update last row
oRS.MoveLast
oRS(0).Value = "test"
oRS.Update
' Add a new row
oRS.AddNew
oRS(0).Value = 7
oRS(1).Value = 8
oRS(2).Value = 9
oRS.Update
Debug.Print oRS.RecordCount
Thanks
Todd
collection corresponding to the requested name or ordinal.
Can anyone tell me why. I get this error near the end of
the code on line "oRS(1).Value = 8"
'Using OLE DB Provider for Jet:
Dim oConn As ADODB.Connection
Dim oCmd As ADODB.Command
Dim oRS As ADODB.Recordset
' Open a connection to the Excel spreadsheet
Set oConn = New ADODB.Connection
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\QTD\Sales.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
' Create a command object and set its ActiveConnection
Set oCmd = New ADODB.Command
oCmd.ActiveConnection = oConn
' This SQL statement selects a cell range in the "Expenses"
' worksheet
oCmd.CommandText = "SELECT * from `Expenses$A2:C4`"
' This SQL statement selects a named cell range
' defined in the workbook
oCmd.CommandText = "SELECT * from `Range1`"
' Open a recordset containing the worksheet data.
Set oRS = New ADODB.Recordset
oRS.Open oCmd, , adOpenKeyset, adLockOptimistic
Debug.Print oRS.RecordCount
' Update last row
oRS.MoveLast
oRS(0).Value = "test"
oRS.Update
' Add a new row
oRS.AddNew
oRS(0).Value = 7
oRS(1).Value = 8
oRS(2).Value = 9
oRS.Update
Debug.Print oRS.RecordCount
Thanks
Todd