01-07-05, 19:36 #1Registered User
- Join Date
- Nov 2002
Unanswered: Undoing new record after error trapping
I have an Access 2002 application in which I have a form and an associated subform. I am trying to, on the subform, trap the error which happens when someone tries to enter a new line in the subform without entering the key value in the Parent form. I can easily trap the error in the subform's on error event, but what I would like to be able to do would be to undo the entry of the new record and setfocus on the key value on the Parent form. What I get is the entered field on the subform focused on after my custom message box has the ok button clicked on it. Below is my code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Dim intResponse As Integer
If DataErr = 3162 Then
SendKeys "^Z", True
intResponse = MsgBox("Please Enter A Job Number On The Form Above.", , "Job Number Needed!")
Response = acDataErrContinue
I have moved all three lines in the if statement around, in all sorts of orientations, to no avail. I have even tried to set the sendkeys to happen after the message box line if intResponse = 1. Is there a good undo docmd or runcommand that would work here? It seems like this should easily work and it is driving me crazy. I haven't yet tried things that seem less elegant solutions to me, like asking through code if the key value on the Parent form is null when focus is put on the subform, but I suppose if that is the alternative I could try that. Thank you in advance for your time and responses.
01-08-05, 05:22 #2Registered User
- Join Date
- Sep 2003
- Caldes de Malavella, Spain
How about this: set the subform's "Allow Additions" property to No. When the user enters the key value in the parent form, change the "Allow Additions" property to Yes. This means that a new record is created in the subform only when there is a parent value. The user will not be able to enter a new record in the subform otherwise.
You can set the property back to "No" after the record in the subform has been updated.
Hope this helps.Andy Briggs
Elmhurst Solutions Limited
Database Development and Consultancy