Run-Time error ‘3265’

T

Tim

Hi folks,

When I ran the following code, I got an error message “Run-Time error
‘3265’â€: Item cannot be found in the collection corresponding to the
requested name or ordinal. And the line of code was highlighted
--!rst1("FieldName").Value = objSheet.Range(rst1("CellID").Value).

Please help me to correct it. Thanks in advance.

Tim.

Public Sub x()

Dim objExcel As Excel.Application
Dim objBook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim rst As New ADODB.Recordset
Dim rst1 As ADODB.Recordset
Dim strFile As String

strFile = Dir("c:\test\*xls")

Do While Len(strFile) > 0
Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Open("c:\test\" & strFile,
ReadOnly:=True)
Set objSheet = objBook.Worksheets("Worksheet")
Set rst = fUpdateRst("tbltest")
Set rst1 = fOpenRst("Select FieldName, CellID from tbltest;")

With rst
.AddNew
Do While Not rst1.EOF
!rst1("FieldName").Value =
objSheet.Range(rst1("CellID").Value)
'!LOName = objSheet.Range("C4")
rst.MoveNext
Loop
.Update
.Close
End With

objBook.Close
objExcel.Quit
rst1.Close

Set rst1 = noting
Set objSheet = Nothing
Set objBook = Nothing
Set objExcel = Nothing
Loop

End Sub
 
O

Ofer

Try and change this line
!rst1("FieldName").Value = objSheet.Range(rst1("CellID").Value)

To
rst(rst1!FieldName) = objSheet.Range(rst1("CellID").Value)
 
T

Tim

Hi Ofer,

It works great. Thanks a lot.

Tim.

Ofer said:
Try and change this line
!rst1("FieldName").Value = objSheet.Range(rst1("CellID").Value)

To
rst(rst1!FieldName) = objSheet.Range(rst1("CellID").Value)
 

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