Undo a record

  • Thread starter Thread starter D B Lawson
  • Start date Start date
D

D B Lawson

Guest
Here's a cracker! I have a form with subforms that are on tab controls (3 subforms). On a Close button I have some code to make sure that the user has completed all the required fields. If they haven't and the click to close the form anyway, the record is set to "Undo". This was working well, I thought, until I found some phantom records with no reason for them. I then discovered that if the user is mucking about, enters some data, clicks the tab controls, looks at the subforms (doesn't create any records within the subform) and then click's to close, the main record doesn't undo! Why! Anybody got any solutions to my problem? When stepping through the code, it looks as if the record is undoing, but it's not. Here is my code:

If (Me.cboJobType) = 1 Or Me.cboJobType = 4 And Not IsNull(Me.JDateEntered) Then

If IsNull(Me.cboLoggedBy) Or Me.JLoggedBy = 0 Then

stdResponse = MsgBox("You have not entered your name in the Logged By field." & vbCr & _
"This is a required field, do you want to complete it now?" & vbCr & vbCr & _
"Select YES to return and select your name." & vbCr & vbCr & _
"Select NO to exit the form WITHOUT SAVING the record.", _
vbYesNo + vbDefaultButton1, "Missing Data")

If stdResponse = vbNo Then '(Default)

Me.Undo
DoCmd.Close
Exit Sub

Else 'vbCancel
Me.cboLoggedBy.SetFocus
Exit Sub
End If
End If
'
End If
 
Look on the Microsoft Download Site... Download the Form Sample Database. On that database, it shows how to correctly undo a record, along with all the subform records.... Hope this helps.

Doug
 
Are these child subforms? If so Pat gave me the reason and a sensible cure.
 
Hi

Yes the subforms are child forms linked to the main form by an ID field. Does that help?

I'll get the sample database from the download site as well.
 
Update:

I tried the code to undo a record as shown in the form samples but keep getting and error message "Can't undo at this time".

Rich, can you give me any more information on the problem?

Appreciate the help, as always

Dawn
 
Problem sorted! Once I understood why it was happening, because the record was being saved to the table on the move the the subform and the undo was too late by then, it was simple! On the Before Update event of the form, I make sure that all the required fields are completed on the main form before letting them move to the subform and cancel the save if everything's not complete.

Many thanks for your help. Now on to the next problem!
 

Users who are viewing this thread

Back
Top Bottom