MS-Access中,VBA和错误处理错误、MS、Access、VBA

2023-09-09 21:21:15 作者:涐﹏、永远开心 ◇

这更是一个观察不是真正的问题:(一般和VBA)MS-访问拼命丢失,其中的错误处理code可以自动生成工具,并在该行数时可显示一个错误发生。你有没有找到一个解决办法?它是什么?我刚刚意识到有多少数百个小时我幸免,因为我找到了正确的答案这个基本问题几年前,我倒要看看你有什么想法和解决方案,在这个非常重要的问题。

This is more an observation than a real question: MS-Access (and VBA in general) is desperately missing a tool where error handling code can be generated automatically, and where the line number can be displayed when an error occurs. Did you find a solution? What is it? I just realized how many hundreds of hours I spared since I found the right answer to this basic problem a few years ago, and I'd like to see what are your ideas and solutions on this very important issue.

推荐答案

我的解决办法如下:

在安装 MZ-工具,一个很有趣的附加为VBA。不,他们没有给我,反正是免费的。 在程序中的标准错误处理程序code像这样的(见MZ工具菜单/选项/错误处理程序): install MZ-Tools, a very interesting add-on for VBA. No they did not pay me, anyway it is free. program a standard error handler code such as this one (see MZ tools menu/Options/Error handler):

On Error GoTo {PROCEDURE_NAME}_Error
{PROCEDURE_BODY}
On Error GoTo 0
Exit {PROCEDURE_TYPE}

{PROCEDURE_NAME}_Error:
debug.print "#" & Err.Number, Err.description, "l#" & erl, "{PROCEDURE_NAME}", "{MODULE_NAME}"

此标准错误code,可以将自动通过点击在MZ-Tools菜单中的相应按钮添加到您所有的特效和功能。你会发现,我们这里指的是VBA(2003年版),ERL,它表示错误路线的一个未公开的价值/属性。你说对了!如果你问MZ-工具来自动编号您的code线,ERL然后给你哪里出错的行号。您将有错误的完整说明在您的直接窗口,如:

This standard error code can be then automatically added to all of your procs and function by clicking on the corresponding button in the MZ-Tools menu. You'll notice that we refer here to an undocumented value/property of VBA (2003 edition), 'erl', which stands for 'error line'. You got it! If you ask MZ-Tools to automatically number your lines of code, 'erl' will then give you the number of the line where the error occured. You will have a complete description of the error in your immediate window, such as:

#91, Object variable or With block variable not set, l# 30, addNewField, Utilities

当然,一旦你意识到了系统的利益,你能想到一个更复杂的错误处理,不仅会显示数据在调试窗口但也将:

Of course, once you realize the interest of the system, you can think of a more sophisticated error handler, that will not only display the data in the debug window but will also:

在显示它的屏幕上的信息 自动插入与错误的描述或 错误日志文件中的行 如果您正在使用Access或如果您连接到一个数据库,记录自动添加到Tbl_Error表! display it as a message on the screen Automatically insert a line in an error log file with the description of the error or if you are working with Access or if you are connected to a database, automatically add a record to a Tbl_Error table!

这意味着可以存储在一个文件或表在用户级别产生的每个误差,机器或网络上的某个地方。我们是在谈论建立一个自动化的错误报告系统使用VBA的工作?

meaning that each error generated at the user level can be stored either in a file or a table, somewhere on the machine or the network. Are we talking about building an automated error reporting system working with VBA?