Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ Access Errors + Error Handling _ Onerror Macro Action Doesn’t Trap Error 2046

Posted by: garai1 Aug 11 2019, 07:59 AM

Hi all,

I’m about to finish developing an application with Access 2016, running on a Windows 10 64-bits system, and so far all has been running as expected. Only issue is that I can’t get the On error macro action to trap error 2046. I have a number of forms that trigger an action when they’re closed. For most of them, the action is simply setting a TempVar, through the SetTempVars action placed in the form’s On Close macro event. I have issued error trapping in the On Close event of all these forms, by means of On Error > Next (equivalent to On error resume next in VBA code). Up to here everything seems to work fine. The problem is, if I close the application before closing any of these forms, then error 2046 raises “The command or action ‘OnError’ isn’t available now”, which means that the error handling routine is not trapping this error. If I remove the onerror action from my macro and quit the application without closing one of these forms, I get same the same error 2046, but this time is : “The command or action ‘SetTempVar’ isn’t available now”. I’m not worried about this error and I don’t need to suppress it, because it’s totally harmless, I just need to trap it so the users don’t have to see the error messages.

Two more tips: this is happening only in my “light” forms (with no VBA module). If I add a module and place the same code in the form’s close event, then the error doesn’t raise; and it only happens in the accdr (runtime mode) application, it doesn’t happen in the accdb file.

Any help will be greatly appreciated (btw, this is my first post in UA).

garai1

Posted by: theDBguy Aug 11 2019, 09:36 AM

Hi. Welcome to UA! welcome2UA.gif

What is the description for error 2046? Just curious...

Posted by: strive4peace Aug 11 2019, 05:03 PM

adding on ... welcome

garai1 (what is your name?),
> "If I add a module"
it seems you have already found the solution to the problem yourself ... it helps to write it down ~

Trigger the code to run whilst still seeing the control values, which can't happen if the application is closing without code behind a form because there's nothing to stop the form from unloading data before values are read.

Another consideration might be to use the form UNLOAD event, which happens just before a form closes and can also be canceled -- instead of Close -- earlier place to happen and larger success for control values being available.



Posted by: garai1 Aug 13 2019, 01:53 AM

Hi theDBguy and strive4peace. Thanks for your answers and welcome greetings. Well, yes, it looks like the solution is adding a module, doing it all with VBA and forget about using macros for these forms. I’ve had this type of errors before with macros in other situations, and I still wonder: why is the error trapping routine in my macros not trapping this error?

Posted by: strive4peace Aug 13 2019, 08:09 AM

hi,
it is hard to say why the macro isn't trapping the error. Is the macro embedded in the form, or a stand-alone macro? Could you post a screen shot of it?

Posted by: garai1 Aug 16 2019, 05:43 AM

I'm attaching three screenshots: two error messages and the code of the embedded macro in the Onclose event of the form that triggered the error. This error rose by closing the application without previously closing the form. First I got the message “The command or action ‘OnError isn’t available now“ and after I clicked “OK”, I got the second error message “Macro single step”, where you can see that the error number is 2046. As you can see, the “Onerror” code obviously didn’t trap this error. If I remove the Onerror command in this macro, then I’ll get the same message, but this time “The command or action ‘SetTempVar’ isn’t available now “. I’ve tried the same macro, but using the Unload, rather than OnClose event and I get the same results. I’m sorry I couldn’t reproduce the error for another situation, because I don’t remember exactly when that happened, but I know it has happened before (and it wasn’t closing the application without closing the form before) and again, it only happens with the runtime version, not when developing and debugging with the accdb file, which makes it sort of difficult to track it. In the meanwhile, I’m adding a module to each of this “light-weight” forms and changing the macros to VBA code, which so far, doesn’t give this error.

 

Posted by: strive4peace Aug 19 2019, 10:58 AM

thanks for the additional information. I've racked my brains but I don't know what to say except RunTime has odd errors and is obviously lacking in the macro-processing department. At least you have a way around it.


Posted by: garai1 Aug 22 2019, 04:58 AM

Yes, right. Thanks a lot anyway. As you said, at least I have a workaround. I guess I should mark this thread as "Resolved". How do I achieve that?