vba Excel 2010:运行时错误 1004 一般 odbc 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28296258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:05:03  来源:igfitidea点击:

Excel 2010: Run time error 1004 general odbc error

excelexcel-vbaexcel-2010vba

提问by Matt

I have a small Excel 2010 query that either times out (not responding) then gets the error Run time error 1004 general odbc error

我有一个小的 Excel 2010 查询,它要么超时(没有响应)然后得到错误 Run time error 1004 general odbc error

When I debug it highlights this line:

当我调试它突出显示这一行:

 Selection.QueryTable.Refresh BackgroundQuery:=False

This was working in Excel 2007.

这在 Excel 2007 中有效。

I tried On Error Resume Nextto get the query to skip any errors and move to the next part but that didn't help.

我试图On Error Resume Next让查询跳过任何错误并转到下一部分,但这没有帮助。

Sub Refresh_all()

    Application.ScreenUpdating = False

    Application.Goto Reference:="querycell"
    Range("A2").Select

    Selection.QueryTable.Refresh BackgroundQuery:=False

    Dim pt As PivotTable
    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets
        For Each pt In ws.PivotTables
            pt.RefreshTable
        Next pt   
    Next ws

    Application.Goto Reference:="returncell"
    Range("A1").Select
    Application.ScreenUpdating = True

End Sub

采纳答案by Matt

Very strange solution to this, but i'm putting it up in case anyone in the future finds them selves in this quandary!

对此非常奇怪的解决方案,但我将其提出,以防将来有人发现自己陷入困境!

In the Command text one of the lines was:

在命令文本中,其中一行是:

WHERE i.c LIKE NVL(?, '%')

Which for some reason worked in Excel 2007 but not in 2010

出于某种原因,它在 Excel 2007 中有效,但在 2010 年无效

By changing it to this it worked as before

通过将其更改为它,它可以像以前一样工作

WHERE i.c = ?

I'm sure someone more intelligent than me will come along and give reasoning behind this, but until then, thats what solved it

我相信会有比我更聪明的人来解释这背后的原因,但在那之前,这就是解决问题的方法