We help IT Professionals succeed at work.
Get Started

update spreadsheet using ADO and Excel in VB6

1,017 Views
Last Modified: 2012-05-10
I am trying to update an Excel spreadsheet using ado in VB6 with some code I found on internet.

I get "Item cannot be found in the collection corresponding to the requested name or ordinal"
Here:
If rc.Fields("Field3").Value = 10 Then

The column header for thr column is named Field3.  What's wrong?


Dim sfile As String
    Dim strQuery As String
    Dim rc As ADODB.Recordset
    Dim cn As ADODB.Connection
    sfile = "C:\Book1.xls"
    Set cn = New ADODB.Connection
    With cn
        .Provider = "MSDASQL"
        .ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};" & _
    "DBQ=T:\Production Control Fabric and Yarn\Scheduling\AFGHAN SCHEDULE (Current)\denise_AFGSCH070610.xls; ReadOnly=False;"
        .Open
    End With

strQuery = "Select * from [looms$C1:C20]"

    Set rc = New ADODB.Recordset
    rc.Open strQuery, cn, adOpenStatic
    MsgBox rc.RecordCount
    MsgBox rc.Fields.Count

    While Not rc.EOF()
        If rc.Fields("Field3").Value = 10 Then
            rc.AddNew
            rc("Field3") = 66
            rc.Update
        End If
        rc.MoveNext
    Wend
cn.Close
Set rc = Nothing

Open in new window

Comment
Watch Question
Senior Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE