Results 1 to 2 of 2
  1. #1
    JayZoll is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2012
    Posts
    1

    Export Data w/FSO - Open object recordset failed

    Hello,
    ***The text in the SQL is case sensitive, the field names in my table were lower case, in the VBA SQL each were capitalized***

    Please help! I am trying to export data using file system object and receive the following error:

    Run-time error '-2147467259 (80004005)'"
    Method 'Open' of object '_Recordset' Failed

    The routine writes a blank .txt file to my desktop. When debugging, it fails rs.Open line. The query is valid and works in query window.

    References selected: Visual Basic For Applications, Microsoft Access 11.0 Object Library, OLE Automation, Microsoft DAO 3.6 Object Library, Microsoft ActiveX Data Objects 2.1 Library, Microsoft Scripting Runtime



    MS Access Version: 2003 Professional Edition (11.6566.8117) SP2

    The "NASDAQ" table:
    date open close
    2006-01-03 10718 10809
    2005-12-01 10806 10717
    2005-11-01 10569 10440



    Code:
     Sub XPORT()
    
    Dim fso As FileSystemObject
    Dim txt As TextStream
    Dim rs As ADODB.Recordset
    Dim s As String
    
    Set fso = New FileSystemObject
    Set txt = fso.CreateTextFile("C:\Documents and Settings\xjp1pyu\Desktop\xportit.txt", True)
    
    Set rs = New ADODB.Recordset
    rs.ActiveConnection = CurrentProject.Connection
    rs.Open "SELECT Date, Open, Close FROM NASDAQ", , adOpenForwardOnly, adLockReadOnly
    
    txt.WriteLine "Date, Open, Close"
    Do While Not rs.EOF
        s = """" & FormatDateTime(rs("Date"), vbShortDate) & """, "
        s = s & FormatNumber(rs("Open"), 2, vbFalse, vbFalse, vbFalse) & ", "
        s = s & FormatNumber(rs("Close"), 2, vbFalse, vbFalse, vbFalse)
        txt.WriteLine s
        
        rs.MoveNext
    
    Loop
    
    rs.Close
    txt.Close
    
    End Sub
    Last edited by JayZoll; 11-12-2012 at 12:58 PM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    This is resolved? Want to share the solution?

    The rs.Open is missing the connection argument parameter.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-03-2012, 01:44 PM
  2. Replies: 1
    Last Post: 07-13-2012, 07:58 PM
  3. Method InsideHeight of object PlotArea failed
    By dgardineer in forum Programming
    Replies: 1
    Last Post: 10-26-2011, 01:52 PM
  4. the operation on the ole object failed
    By merlin777 in forum Access
    Replies: 5
    Last Post: 09-05-2011, 05:43 PM
  5. Replies: 1
    Last Post: 07-17-2010, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums