Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel Record Button

Status
Not open for further replies.

AT76

Technical User
Apr 14, 2005
460
US
Hi,

I'm hving a rough time with this button. I would like to give the user of this database access to save or delete the record he/she is working on when they exit the form. This is what I've done:

Private Sub Form_Close()
Dim strMsg1 As String
Dim strMsg2 As String
Dim strMsg3 As String
strMsg1 = strMsg1 & "Data has changed. "
strMsg2 = strMsg1 & "Do you wish to save changes? "
If MsgBox(strMsg2, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
'do nothing
Else

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

End If

End Sub

I understand that: DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
is supposed to delete the record but in my case it still gets saved. Any ideas why this might be?

Thank you.
 
One other question, If I have a subform in this form will it delete record created in the subform aswell?

Thanks...
 
Try to delete instead of undoing. Try this:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.Close

Maybe it will help.
 
I'm guessing the form close event triggers after the before update event of the form, which is where you can cancel or not a save.

If you are going to do something with regards to preventing or not a save when a form closes, I think that event (forms before update event) needs to be involved. Here's one thread, with some further linking thread702-1080271.

Isn't this a bit more about form coding than VBA/Modules? Wouldn't perhaps the forms forum be a forum more correct for this question (forum702?)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top