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
> Error 3022 Recovery, Access 2016    
 
   
RiverKing
post Feb 14 2018, 01:12 PM
Post#1



Posts: 158
Joined: 5-August 13
From: North Texas (DFW)


My app is trapping Err 3022 very nicely but how can I reset Access to its state before the error occurred?

When the user attempts to add a new record with a duplicate key, the Form On Error Event invokes a Private Sub (via Event Procedure) as described in UtterAccess's documentation of the Error Event. My procedure uses MsgBox to display a custom message, issues Err.Clear, DoCmd.CancelEvent, and ActiveControl.Undo commands, and sets Response = acDataErrContinue before returning to Access. So far, so good.

But regardless of what the user then does (changes the key field entered or closes the app), the Error Event is triggered again. Interestingly enough, the "duplicate" key Control has the updated non-duplicate value (or a null string if the user spaced out or deleted the Control).

What do I have to do to allow the user to try again or forget the whole thing as though he did not enter the duplicate key in the first place?


Go to the top of the page
 
theDBguy
post Feb 14 2018, 01:15 PM
Post#2


Access Wiki and Forums Moderator
Posts: 73,941
Joined: 19-June 07
From: SunnySandyEggo


Hi Chuck,

Do you know if you're getting the error because Access is trying to save the record? If so, then try undoing the form rather than just the control.

Hope it helps...
Go to the top of the page
 
RiverKing
post Feb 14 2018, 02:52 PM
Post#3



Posts: 158
Joined: 5-August 13
From: North Texas (DFW)


ActiveForm.Undo did the trick! Many thanks.

fyi, the Err.Clear and DoCmd.CancelEvent were then unnecessary...but you probably knew that.

The ActiveForm.Undo cleared the user's entry though. I wanted the user to be able to see the error after clicking OK on my error message and then be able to correct it or eliminate the entry. Saving the ActiveControl string before issuing the ActiveForm.Undo and then restoring it before returning control to Access resolved that issue exactly the way I had hoped.

Again, thank you very much for the quick and, more importantly, correct solution to my problem.


Go to the top of the page
 
theDBguy
post Feb 14 2018, 02:57 PM
Post#4


Access Wiki and Forums Moderator
Posts: 73,941
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Glad to hear you got it sorted out. Good luck with your project.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    14th December 2018 - 11:01 AM