In an access database I have a small function that is called on startup that registers a piece of software for generating barcodes.
When the software is not installed then then Microsoft access runtime errors out, So i would like to add some proper error handling that informs the user of what is causing the problem.
This function is called from a macro on startup and is crashing the database rather than the error handling working properly.
Is my error handling incorrect?
Public Function LicenseTBarCode()
On Error GoTo Err_LicenceTBarCode
Dim TB As New TBarCode10
TB.LicenseMe "<EXPUNGED>", eLicKindSite, 1, "<EXPUNGED>", eLicProd1D
Set TB = Nothing
Exit Function
Err_LicenceTBarCode:
MsgBox "TBarcode Software is not installed. Please contact the database administrator.", vbExclamation, Error
DoCmd.Quit
End Function
Change your code to use late binding:
In order for this to work well, you will really need to use late binding for all of your TBarCode code, including any other TBarCode objects you might be using. If you’re not already familiar with Late Binding it can be a little challenging to understand at first, especially if you are working with any classes that use the factory pattern.
With late binding, you will uncheck your reference to the DLL and then your code needs to compile without errors. Developing with Late Binding can be challenging since you will not have access to IntelliSense. It works best to develop with Early Binding and then convert your code over to Late Binding later.
Another thing you lose with Late Binding is any constants that were defined in the original object. You have to create these yourself. Depending on how many you need to use and where all you need to use them, it might be simplest to create a module just to hold these constants. You really only need to have the constants that are actually used in your code.
Alternately, you can just use the values that the constants contain. For example:
Also, to my knowledge Late Binding does not work with ActiveX controls. ActiveX Controls are inherently early bound.
There is another way to handle this problem. I use a “starter” database file that handles some of the prerequisites for the main database. This starter database doesn’t use any references. It only checks the file system to see if the correct files are installed. If they are not, it pops up a messagebox with the correct errors/warnings and then it either runs the main database file or chooses not to run it, depending on the logic you’ve written into it. This is one way to avoid using Late Binding.