UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Onerror Macro Action Doesn’t Trap Error 2046, Access 2016    
 
   
garai1
post Aug 11 2019, 07:59 AM
Post#1



Posts: 4
Joined: 7-August 19



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
Go to the top of the page
 
theDBguy
post Aug 11 2019, 09:36 AM
Post#2


Access Wiki and Forums Moderator
Posts: 76,405
Joined: 19-June 07
From: SunnySandyEggo


Hi. Welcome to UA! welcome2UA.gif

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

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
strive4peace
post Aug 11 2019, 05:03 PM
Post#3


strive4peace
Posts: 20,459
Joined: 10-January 04



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.



--------------------
have an awesome day,
crystal
Go to the top of the page
 
garai1
post Aug 13 2019, 01:53 AM
Post#4



Posts: 4
Joined: 7-August 19



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?
Go to the top of the page
 
strive4peace
post Aug 13 2019, 08:09 AM
Post#5


strive4peace
Posts: 20,459
Joined: 10-January 04



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?

--------------------
have an awesome day,
crystal
Go to the top of the page
 
garai1
post Aug 16 2019, 05:43 AM
Post#6



Posts: 4
Joined: 7-August 19



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.
Attached File(s)
Attached File  Error_message_1.JPG ( 30.59K )Number of downloads: 2
Attached File  Error_message_2.JPG ( 33.5K )Number of downloads: 2
Attached File  Macro_code1.JPG ( 55.1K )Number of downloads: 4
 
Go to the top of the page
 
strive4peace
post Aug 19 2019, 10:58 AM
Post#7


strive4peace
Posts: 20,459
Joined: 10-January 04



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.


--------------------
have an awesome day,
crystal
Go to the top of the page
 
garai1
post Aug 22 2019, 04:58 AM
Post#8



Posts: 4
Joined: 7-August 19



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?
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th October 2019 - 12:11 PM