Do not add record (1 Viewer)

Gorio

Registered User.
Local time
Today, 18:35
Joined
Sep 26, 2000
Messages
33
I'm trying to write what must be simple code. Quit simply, when the user want to close a form, do they want to save this new record or not? I've gotten this far, but am not sure how to discard all the entries on this new record. There is one link to another table on this form. This form holds the many of a one to many.

Private Sub cmdClose_Click()

Dim msgSave As Variant

msgSave = MsgBox("Do you wish to save this Class Info?", _
vbYesNoCancel, "Save Class Info")

If msgSave = vbYes Then
DoCmd.Save
Exit Sub
ElseIf msgSave = vbNo Then
docmd.??????
ElseIf msgSave = vbCancel Then
Exit Sub
End If

End Sub
 

cargobay 69

Registered User.
Local time
Today, 18:35
Joined
May 1, 2001
Messages
25
I haven't tried this, but it should work. Try using this code where the user selects to not save the new record:

SendKeys "{ESC}" 'Clear current field
SendKeys "{ESC}" 'Clear current record
DoCmd.Close

Darrin - CB69
 
R

Rich

Guest
Either Me.Undo or SendKeys"{ESC}","{ESC}"
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:35
Joined
Feb 19, 2002
Messages
43,484
You cannot use the close event for this purpose since by the time the close event is fired, the record has already been saved.

You need to move the question to the BeforeUpdate event of the form and cancel the update if the user chooses not to save the record.

Dim msgSave As Integer
msgSave = MsgBox("Do you wish to save this Class Info?", _
vbYesNoCancel, "Save Class Info")
If msgSave = vbYes Then
Else
If msgSave = vbNo Then
cancel = True
Me.Undo
Else
Cancel = True
End If
End If
 

Users who are viewing this thread

Top Bottom