访问 VBA 错误 0(零)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22520907/
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
Access VBA Error 0 (zero)
提问by User1
I have an Access 2007 database. It uses SharePoint 2010 linked lists as the tables. I have multiple forms that keep getting an error number "0". I get this error in these scenarios:
我有一个 Access 2007 数据库。它使用 SharePoint 2010 链接列表作为表。我有多个表单不断收到错误编号“0”。我在这些情况下收到此错误:
click in a comboBox, that uses a SharePoint list as its source, then type text that is not on the list. (the "limit to list" property must be true). If this property is false, then I don't get the error and everything works fine, but this must be set to true for this specific database.
lose connection to SharePoint, then click on an object (comboBox etc) that uses a SharePoint list as its source. There is code in an "Got_Focus" sub that pulls data from the list.
单击使用 SharePoint 列表作为其源的组合框,然后键入不在列表中的文本。(“限制到列表”属性必须为真)。如果此属性为 false,那么我不会收到错误并且一切正常,但是对于此特定数据库,必须将其设置为 true。
失去与 SharePoint 的连接,然后单击使用 SharePoint 列表作为其源的对象(组合框等)。“Got_Focus”子程序中有从列表中提取数据的代码。
If I catch error number 0 and take care of that, immediately after, the real description displays. For instance, in the first scenario after catching 0 the error "item not on list" box will show, which is a real error (2237) and the second a "can't find record source" box will show, error 2580. However, I can't catch those errors, and if I put in a message box to display the error number after catching error 0, it never displays/or activates.
如果我发现错误号 0 并处理它,紧接着就会显示真实的描述。例如,在捕获 0 后的第一个场景中,将显示错误“项目不在列表中”框,这是一个真正的错误 (2237),第二个“找不到记录源”框将显示,错误 2580。但是,我无法捕捉到这些错误,如果我在捕捉到错误 0 后放入一个消息框以显示错误编号,它永远不会显示/或激活。
It seems I get the error 0 consistently when the "Limit to list" property is set to true. I've tried to do "On_Load" sub set Limit to List to true, and "On_close" set to false, however this causes an error can't find object on the "On_Close()" sub. Here is a sample:
当“限制到列表”属性设置为 true 时,我似乎始终收到错误 0。我尝试将“On_Load”子集限制到列表设置为true,并将“On_close”设置为false,但是这会导致在“On_Close()”子集上找不到对象的错误。这是一个示例:
Private Sub Got_Focus()
On Error GoTo catchError
Me.Requery \This could be any code that "pings" the SharePoint List
exit_catchError:
Exit Sub
catchError:
If Err.Number = 0 Then Resume Next \i'v tried with and without this. Gives error 20 with
\ Also tried If Then with Err.Number = 0
If Err.Number = 2580 Then \Doesn't catch
MsgBox "Reconnect to SharePoint"
ElseIf Err.Number = 2237 Then \Doesn't catch
MsgBox "Text not on List"
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub
回答by pteranodon
Error code 0 indicates the absence of an error condition. The only time I've seen a messagebox about Error 0 is when I have missed putting Exit Sub
before the error handler. If you take the Exit Sub
out of your code above, the body of the sub will run and then the error handler will start. The Else
clause will run, prompting a message box with just 0 in it. Is this a possibility?
错误代码 0 表示不存在错误条件。我唯一一次看到关于错误 0 的消息框是我错过了Exit Sub
在错误处理程序之前放置。如果你去掉Exit Sub
上面的代码,子的主体将运行,然后错误处理程序将启动。该Else
子句将运行,提示一个只有 0 的消息框。这是一种可能性吗?
回答by User1
I fixed it by using DataErr rather than Err.Number. I also took out the else statement to show a msgbox. It seems to work just fine now.
我使用 DataErr 而不是 Err.Number 修复了它。我还拿出else语句来显示一个msgbox。它现在似乎工作得很好。
回答by Vic Fanberg
I just tracked down something like this where I would get an "error 0" displayed in a control whenever the source of the control was a formula; but if it was just a table column, it had no error. For example, if the source of the control was "[colA]", no error message. If the source of the control was "=[colA]", get an "Error 0" message. The problem turned out to be that the control had defaulted to the name "colA". The fix was to rename the control.
我刚刚找到了这样的东西,只要控件的源是公式,我就会在控件中显示“错误 0”;但如果它只是一个表列,它没有错误。例如,如果控件的来源是“[colA]”,则没有错误消息。如果控件的源是“=[colA]”,则会收到“错误 0”消息。问题原来是控件默认使用名称“colA”。解决方法是重命名控件。