简体   繁体   中英

Run Code after any VBA (MS Access) error

I am developing for an error logging application for data centers that use MS Access. In the test environment there are +- 200 MS Access MDBs. I at the point where my application will run on one MDB perfectly fine. I have achieved the MDB specific functionality by inserting code into each and every On_Error function, and by wrapping any function in such an On_Error catch statement. My problem is that to alter each and every database and each and every function in each of those would be redundant. Is there anyway to add some code/module to each MDB just in one place that would be run on any error? (Alternatively is there a way to open and alter the VBA behind the forms programmically, even if it involves ridiculous string-manipulation.)

You can link a centralized library mdb/mde as per DaveMac's link, but error handling ("On Error ...") needs to be local in each and every function. That's just how it is in VBA.

Using the VBIDE object library, you can access and modify VBA code in other databases. See

Import lines of code

https://christopherjmcclellan.wordpress.com/2014/11/06/meta-programming-in-vba-the-vbide-and-why-documentation-is-important/

It will be quite a bit of work though, I think. I only ever used this to copy modules from one (Word) file to a couple of other files, and it took some time to get it right.

Note that using http://www.mztools.com/v3/mztools3.aspx you can add a customizable error handler to a function with one click (or shortcut). Doing it with VBIDE might not be the faster way in the end, but surely more fun. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM