Results 1 to 4 of 4

Access Stored Procedure Automation Error

Threaded View

  1. #1
    Registered User
    Join Date
    08-08-2014
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    4

    Access Stored Procedure Automation Error

    Hi All

    I have a stored query procedure that executes fine in MS Access, but when I use the ADO library to execute said stored query procedure, and return the results to Excel, I receive an 'Automation error unspecified error -2147467259 (800004005)'.

    It appears to be when it tries to open the recordset (rst. open Source:=...etc), I've included both the VBA that calls the open procedure and the open recordset procedure code itself.

    Any help would be greatly appreciated.

    Cheers.

    Code:
    Sub retirve_query(query_name As String)
    
        Set process_simba_ws = Sheet6
        Set checks_data_ws = Sheet5
        header_rw = 1
        fst_col = 1
        Dim header_rng As Range
    
        On Error GoTo ERROR_RETRIEVEQUERY
        Application.Interactive = False
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
    
        ' Clear previous data
        checks_data_ws.Rows.EntireRow.Delete
    
        create_db_connection
        open_record_set query_name
        
        ' Populate column headers
        For Each fld In rst.Fields
            checks_data_ws.Cells(header_rw, fst_col).Offset(0, i) = fld.Name
            i = i + 1
        Next fld
        
        ' Populate query data
        checks_data_ws.Cells(header_rw + 1, fst_col).CopyFromRecordset rst
        
        ' Format columns
        With checks_data_ws
            .Columns.EntireColumn.AutoFit
            .Rows(1).Font.Bold = True
            .Activate
        End With
        
        ' Update header's formatting
        With checks_data_ws
            lst_col = .Cells(header_rw, .Columns.Count).End(xlToLeft).Column
            Set header_rng = .Range(.Cells(header_rw, fst_col), .Cells(header_rw, lst_col))
            header_rng.Font.Bold = True
            header_rng.Interior.Color = 13553360
            .Cells(header_rw, fst_col).Activate
        End With
    
        close_rst
        close_cnn
    
    EXIT_RETRIEVEQUERY:
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    Application.Interactive = True
    On Error GoTo 0
    Exit Sub
    
    ERROR_RETRIEVEQUERY:
    MsgBox Err.Description
    GoTo EXIT_RETRIEVEQUERY
    End Sub
    Open recordset code:
    Function open_record_set(query_name As String)
    
        ' Create a new recordset
        Set rst = CreateObject("ADODB.Recordset")
        ' Define recordset's attributes
        rst.CursorLocation = 3 'adUseClient
        rst.Open Source:=query_name, _
                 ActiveConnection:=cnn, _
                 CursorType:=2, _
                 LockType:=3, _
                 Options:=4 'adCmdStoredProc
                 
        Set open_record_set = rst
    
    End Function
    Last edited by duftnich03; 01-16-2020 at 05:37 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] ADO To Access SQL Stored Procedure Returning Error
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-07-2015, 07:40 AM
  2. SQL Stored Procedure From Excel
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 05-22-2015, 07:17 AM
  3. How to get stored procedure result in vba?
    By vvickyy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-11-2013, 01:38 AM
  4. Replies: 0
    Last Post: 10-02-2012, 03:06 PM
  5. Use SQL Stored Procedure
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-13-2011, 05:15 PM
  6. Automation error when opening Access database
    By GWB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2010, 05:04 PM
  7. stored procedure
    By qwertyjjj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2007, 01:02 PM

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