Vba ошибка 80004005

  • Remove From My Forums
  • Question

  • Hi everybody, 

    i’m experiencing some difficulties finding a solution to the following problem: I want to connect through a VBA code my Excel file to my Access Database but when it tries to open the recordset it gives me back this error: «Run-Time error ‘-2147467259
    (80004005)’ Automation errore Unspecified Error» and I really cannot find out why.

    The code is as here below: 

                       

    Dim oConn As ADODB.Connection
    Dim oRs As ADODB.Recordset
    Dim sConn As String
    Dim sSQL As String
    Dim StrDBPath As String

    StrDBPath = «K:MyPathTender Tool DB.accdb»
    sConn = «Provider=Microsoft.ACE.OLEDB.12.0;» & _
                                 «Data Source=» & StrDBPath & «;» & _
                                 «Persist Security Info=False;»

    Set oConn = New ADODB.Connection
    oConn.Open sConn
    sSQL = «SELECT TenderDatabase.ContractID, TenderDatabase.Start, TenderDatabase.End, TenderDatabase.Duration, TenderDatabase.TC, TenderDatabase.PCN, TenderDatabase.PCNDescsription, TenderDatabase.ReqQty,
    TenderDatabase.UnitPrice, TenderDatabase.Value FROM TenderDatabase WHERE
    (TenderDatabase.MBE=»»070561688″»);»
    Set oRs = New ADODB.Recordset
    oRs.Open sSQL, oConn, adOpenStatic, adLockBatchOptimistic, adCmdText
    DataArray = oRs.GetRows()
    DataArray = Application.Transpose(DataArray)
    Sheet1.Range(«B9:B1000»).Value = DataArray

     The error appears at this line: oRs.Open sSQL, oConn, adOpenStatic, adLockBatchOptimistic, adCmdText Thank you so much!!

Answers

  • Hi everybody, 

    i’m experiencing some difficulties finding a solution to the following problem: I want to connect through a VBA code my Excel file to my Access Database but when it tries to open the recordset it gives me back this error: «Run-Time error ‘-2147467259 (80004005)’
    Automation errore Unspecified Error» and I really cannot find out why.

    The code is as here below: 

                       

    Dim oConn As ADODB.Connection
    Dim oRs As ADODB.Recordset
    Dim sConn As String
    Dim sSQL As String
    Dim StrDBPath As String

    StrDBPath = «K:MyPathTender Tool DB.accdb»
    sConn = «Provider=Microsoft.ACE.OLEDB.12.0;» & _
                                 «Data Source=» & StrDBPath & «;» & _
                                 «Persist Security Info=False;»

    Set oConn = New ADODB.Connection
    oConn.Open sConn
    sSQL = «SELECT TenderDatabase.ContractID, TenderDatabase.Start, TenderDatabase.End, TenderDatabase.Duration, TenderDatabase.TC, TenderDatabase.PCN, TenderDatabase.PCNDescsription, TenderDatabase.ReqQty,
    TenderDatabase.UnitPrice, TenderDatabase.Value FROM TenderDatabase WHERE
    (TenderDatabase.MBE=»»070561688″»);»
    Set oRs = New ADODB.Recordset
    oRs.Open sSQL, oConn, adOpenStatic, adLockBatchOptimistic, adCmdText
    DataArray = oRs.GetRows()
    DataArray = Application.Transpose(DataArray)
    Sheet1.Range(«B9:B1000»).Value = DataArray

     The error appears at this line: oRs.Open sSQL, oConn, adOpenStatic, adLockBatchOptimistic, adCmdText Thank you so much!!

    In principle, I’d expect the code to work. I just tested it from an Excel workbook, querying a simple database and table of my own, and it worked fine.  Could there be problem with the path or permissions?  If you put the same code (minus the Excel-related
    items) into an Access database, does it work there? Is the ACE provider installed on the system where you are running this code?


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by

      Thursday, February 27, 2014 9:21 AM

First i did looked at other threads and all the answer specified were didn’t helped, as i was getting this error only for specific SQL execution. Whenever i am trying to run SQL with select * from dual i was getting below error message.

enter image description here

Below is my VBA Code

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
    StrCon = "Driver={Microsoft ODBC for Oracle}; " & _
            "CONNECTSTRING=(DESCRIPTION=" & _
            "(ADDRESS=(PROTOCOL=TCP)" & _
            "(HOST=dhotname)(PORT=1521))" & _
            "(CONNECT_DATA=(SERVICE_NAME=APSQ))); uid=username; pwd=password;"
cn.Open (StrCon)
vSQL = "select * from request" 
rs.Open vSQL, cn

Community's user avatar

asked Apr 1, 2016 at 21:52

Akshay's user avatar

7

I am putting solution here, which worked for me. In other similar post it was more over connectivity issue, but in my scenario it was one of the column in table i am trying to access. In my table i had column which is having timeStamp and that’s the column was causing above error, when i removed or used formatting for that column it worked without exception. I wonder if this error would have been more explanatory, as i spend time on trying other stuff instead of just fixing my SQL.

Solution:

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
    StrCon = "Driver={Microsoft ODBC for Oracle}; " & _
            "CONNECTSTRING=(DESCRIPTION=" & _
            "(ADDRESS=(PROTOCOL=TCP)" & _
            "(HOST=dhotname)(PORT=1521))" & _
            "(CONNECT_DATA=(SERVICE_NAME=APSQ))); uid=username; pwd=password;"
cn.Open (StrCon)
vSQL = "select request_id,user_name from request" 
rs.Open vSQL, cn

Now if you look at above example i have specified exact column names, the issue here was REC_DT column which had time value. Either you can convert that value or remove column, for me that value was not required so just removed from my SQL and it worked.

enter image description here

answered Apr 1, 2016 at 21:55

Akshay's user avatar

AkshayAkshay

6472 gold badges17 silver badges37 bronze badges

Permalink

Cannot retrieve contributors at this time

title description author manager localization_priority search.appverid audience ms.topic ms.author ms.custom appliesto ms.date

Run-time error-2147467259 (80004005) when you set a property of a chart

Describes a problem in which you receive a run-time error message when you programmatically set a property of a chart in Excel. Provides a workaround for this problem.

helenclu

dcscontentpm

Normal

MET150

ITPro

troubleshooting

luche

CSSTroubleshoot

Excel for Microsoft 365

Excel 2019

Excel 2016

Excel 2013

Excel 2010

Microsoft Excel 2007

3/31/2022

Run-time error-2147467259 (80004005) when you set a property of a chart

Symptoms

Consider the following scenario:

  • You have a macro that sets a property of a chart in Microsoft Excel. For example, the macro sets the MaximumScale, MinimumScale, Title, Axis, or Legendproperty of a chart.
  • You protect the worksheet. When you do this, you click to select the Edit objects check box in the Protect Sheet dialog box.
  • You run the macro.

In this scenario, you receive an error message that resembles one of the following.

Error message 1

Run-time error '-2147467259 (80004005)':

Method 'MaximumScale' of object 'Axis' failed

Error message 2

Run-time error '-2147467259 (80004005)':

Automation error

Unspecified error

Cause

This problem occurs because the Excel object model for the chart is disabled on a protected worksheet.

Workaround

To work around this problem, unprotect the worksheet to enable the macro to run. You can manually unprotect the worksheet or by using the Unprotect method in the macro.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the «Applies to» section.

I have a problem which I can not get my head around. I have an Access database where I am trying to create a set of queries in by using VBA in Excel by use of ADODB.

I have several queries that are successfully created, ie. the one below here. The second will however not work. If I copy the query manually to the access database (From SELECT and forward) and save is as «DK_Teledata_1» it works perfect

CREATE PROCEDURE DK_Aktiviteter_Union_1 AS SELECT DK_Aktivitet.År FROM DK_Aktivitet;

And the one that does not work

CREATE PROCEDURE DK_Teledata_1 AS SELECT DK_Teledata.Dato FROM DK_Teledata INNER JOIN Time_Intervals ON DK_Teledata.Interval = Time_Intervals.Time_Interval;

The following queries with the same data are created without any problems:

CREATE PROCEDURE DK_Teledata_1 AS SELECT * FROM DK_Teledata;
CREATE PROCEDURE DK_Teledata_1 AS SELECT * FROM Time_Intervals;
CREATE PROCEDURE DK_Teledata_1 AS SELECT * FROM Time_Intervals, DK_Teledata;

As soon as I create the join or use a «WHERE DK_Teledata.Interval = Time_Intervals.Time_Interval» it fails.

The fields Intervals and Time_Intervals are both Text fields with the same length and properties.

Using Excel 2010, accdb database file and «Microsoft.ACE.OLEDB.12.0» provider string.

Hello,

I am really struggling to find the cause of this error, so any help would be really appreciated. I apologize for the long post, but I wanted to get as much information
out there as possible.

I have an excel workbook that contains several spreadsheets, a form, 3 modules of code and several classes. The form loads automatically and runs some code when
the workbook is opened. The form also provides a basic interface to the spreadsheets contained in the workbook and can be closed at any point. No code is executed when the form is closed.

The two errors above only occur when the following conditions are met:

1. The form is closed and no code is being executed

2. During editing of either the code for the form (or a module / class), or the editing of an actual spreadsheet in the workbook.

3. Once the editing has begun, the System error &H80004005 appears at some point either during an autosave or when the workbook is manually saved.

4. The system error is immediately followed by catastrophic error &H8000FFFF (Which typically pops up repeatedly about 10 times forcing you to press «OK» each
time it pops up). Sometimes only the catastrophic error appears, but it will always force you to click OK at least 10 times.

5. Occasionally, during a manual save, the following message appears: “Errors were detected while saving ‘D:filename’. Microsoft Office Excel
may be able to save the file by removing or repairing some features. 
To make the repairs in a new file click Continue. To cancel saving the file, click Cancel.”

Upon clicking continue, you are given the option to give a name to the file excel will attempt to recover to. 
I then get the Catastrophic error message about 10 more times followed by a second message with the following information: “Excel encountered errors during the save. However, Excel was able to minimally save your file to c:Users~AppDataRoamingMicrosoftExcelXL57F1.xlsb”

This file will contain only the raw data and formulas on the spreadsheets in the work book, but all formatting, modules, userforms, and classes will be lost.

Upon clicking cancel, the save operation is discontinued. The next time you manually save, or the next time the system auto saves, the catastrophic failure message
appears with the same repetition.

Other observations:

-Once the error appears it is impossible to save any work unless you manually copy the code into notepad or another application. If you were editing the layout
or information on a spread sheet, those changes will be lost period.

-Excel will attempt to fix the file for you, but it will report back that that the file was so corrupted that the only information it was able to save was the
spreadsheet values and formulas in a separate workbook. All formatting, code modules, classes, and forms will be lost unless you have saved a back up copy somewhere (which I fortunately had).

-There does not seem to be any one action that triggers the event. It may take only a minute or two before the error appears, or several minutes to 15 minutes
before the error appears.

— Once the error appears once, starting the macro will immediately cause a catastrophic error.

In my opinion the problem does not seem to be with the code that has been written for the following reasons:

1. The error only occurs once the macro has been stopped and no code is running.

2. Further, the error only occurs once I attempt to edit code or a sheet in the workbook. Either of those events seems to set the system up for failure on the
next save / autosave.

What I have tried:

1. I did go through my coded to try to attempt to isolate what the problem might be IF my code was causing the problem. At this point, I have no indication what
portion of the code is causing problems, though it is likely something that was added within the last few days since the problem did not occur previous to that point. The difficulty is that nothing seems to change the result. Even rolling back seems to show
the same problem now.

2. Thinking maybe I had some corruption in one of the modules or in the form, I manually copied out all code to individual notepad files and saved them including
the code for the User form. I then open a new clean workbook and added new blank modules then manually copied in the code. I created a new user form and recreated all the controls and manually added the code back into that as well. All of the worksheets we
copied from the old workbook. the initial save was ok, but after closing and reopening the workbook, the same problem showed up within 5 minutes.

3. Since nothing seemed to point to a direct problem with a portion of the code I thought maybe that I had a corrupted install of excel 2010. I reinstalled excel
2010, and then later reverted to excel 2007 on a cleanly built system. Unfortunately the same problem still exists even after this.

4. After doing some searching on the internet I ran across a post that mentioned that after multiple times of editing code on a project, VBA will tend to start
carrying some baggage that can cause weird errors to appear. They mentioned the use of a VBA cleaner addin to clean all of the code in a project. At this point, I felt it was worth a try and installed the addin. It initially seemed to work, but after a few
minutes, the same errors showed up.

Code cleaner url:

http://www.appspro.com/Utilities/CodeCleaner.htm

forum link:

http://www.eggheadcafe.com/software/aspnet/30567799/excel-2007-crash-on-save.aspx

 and

http://www.xtremevbtalk.com/showthread.php?t=102075

I am not ruling out the possibility that something in the code I have written could be causing the error, but it seems unlikely since the code runs fine initially
and the error appears only once the form is closed and you attempt to do any editing to the workbook.

Other information:

OS: Windows 7 64 bit

Microsoft Office Versions: 2007 & 2010


Jackof33trades

Понравилась статья? Поделить с друзьями:
  • Vba вызов ошибки
  • Vba вывод ошибки
  • Vba вывести сообщение об ошибке
  • Vba word обработка ошибок
  • Vba msgbox ошибка