Full Version: exiting a form
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
lnor67
I've got a form (frmEntry) with a subform (frmInspection). When a user chooses to exit without saving, the record is still saved. I've got the Exit button on frmEntry and the only way it is exiting without saving is if the user doesn't touch the subform. here is my code for my exit button:

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click

Me.Undo
DoCmd.Close

Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click

End Sub


If the user enters something on the subform, then decides to exit, a message box pops up asking "Do you want to save?" and even when clicking "no", the record is still saved. ANY ideas??
dashiellx2000
Add Me!sfrmName.Form.Undo.
lnor67
Thanks for your quick response. Unfortunately, I am still having the same problem. Should I put the code somewhere else?

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click

Me.Undo
Me!sfrmInspection.Form.Undo
DoCmd.Close

Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click

End Sub
dashiellx2000
That is the only way I know how to use Undo on a subform. I use it and have a problem occasionally, but most of the time it does work. The other option would be to delete the record from the tbl the sfrm is bound to on the vbNo from your save message.
lnor67
Ok, I'll mess around with it a little more........how would I delete the record from the table on the vbNo?
HiTechCoach
Your code will work fine for a form that does not have a sub form..

When you have a form with a sub form, Access automatically saves the parent record when you enter the sub form. It must do this to insure the at the parent record has been created so the sub form records can have a record to link to.

The method ("logic") of what you want to do is difficult to do when the form/sub form design uses forms that are "bound" to tables. Because you are dealing with multiple records when using a form with sub forms and Access automatically saves a record when you change records or enter a sub form, you will probably need to try this using a different method .

Hope this helps...
danieldunn10
I had this problem also, i sorted it and my thread was here

Hope it helps
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.