+ Reply to Thread
Results 1 to 6 of 6

macro returns error "Method 'Open' of object '_Recordset' failed"

Hybrid View

  1. #1
    Registered User
    Join Date
    08-02-2009
    Location
    c:\Wonderland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: macro returns error "Method 'Open' of object '_Recordset' failed"

    Can anyone help please?

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: macro returns error "Method 'Open' of object '_Recordset' failed"

    Hi

    I could get it to work by enclosing the field names in square brackets:

    Sub aaa()
      Range("B:C").ClearContents
      Set cn = CreateObject("adodb.connection")
      Set rs = CreateObject("adodb.recordset")
      
      cn.Open "provider=microsoft.jet.oledb.4.0;data source = C:\Documents and Settings\Lenovo_User\My Documents\My Data Sources\upcdirectory;extended properties = ""text; hdr=yes"""
      For Each ce In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
      
        rs.Open "select [size],[description] from items.csv where [UPC] = " & ce.Value, cn, 3, 3
        Cells(ce.Row, 2).CopyFromRecordset rs
        rs.Close
      Next ce
      
      
      
      Set rs = Nothing
      Set cn = Nothing
      
    End Sub
    Richard
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Registered User
    Join Date
    08-02-2009
    Location
    c:\Wonderland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Talking Re: macro returns error "Method 'Open' of object '_Recordset' failed"

    Works great! Richard you are wonderful. Thank you so much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1