+ Reply to Thread
Results 1 to 6 of 6

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

Hybrid View

Leafgreen macro returns error "Method... 08-03-2009, 12:10 AM
royUK Re: problem using Vlookup... 08-03-2009, 02:45 AM
Leafgreen Re: macro returns error... 08-04-2009, 04:17 AM
Leafgreen Re: macro returns error... 08-09-2009, 03:49 AM
Richard Schollar Re: macro returns error... 08-09-2009, 05:18 AM
Leafgreen Re: macro returns error... 08-09-2009, 05:40 AM
  1. #1
    Registered User
    Join Date
    08-02-2009
    Location
    c:\Wonderland
    MS-Off Ver
    Excel 2007
    Posts
    5

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

    Re: http://www.excelforum.com/excel-prog...ml#post2138532, this is *exactly* the issue that I have. I think Djvice was working with the same UPC db file that I dl from the web, too. I loaded the files in the zip on that thread and got the lookup macro to work fine.

    But then I tried with my data file. The dl data file "items.csv" has 1,048,571 rows of data. I renamed djvice.xls to mylookup.xls. I edited the macro to this
    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
    where items.csv is my data file. For the header, in the first three cells of the first row of this data file I have inserted "UPC", "size" and "description". When I run the macro I get this error message from MS VB:
    Run-time error '-2147467259 (80004005)':
    Method 'Open' of object '_Recordset' failed


    Help, please. TIA
    Last edited by Leafgreen; 08-03-2009 at 04:32 AM. Reason: title correction

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: problem using Vlookup from another post here

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    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"

    Ok I changed the title. How's that look?

  4. #4
    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?

  5. #5
    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

  6. #6
    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