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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel Save Changes 2

Status
Not open for further replies.

RobCPA

Programmer
Nov 6, 2002
110
US
I have a form that has a close button. If the record has been modified and the record has not saved (the record is 'dirty'), then a message box appears asking the user if the record should be saved.

My problem is that even if the user selects no and the cancel event happens, the routine still goes to the BeforeUpdate method and the record is still saved with the changes, even though the user has selected 'no'. The code is below:


Private Sub cmdClose_Click()
Dim retval As Variant
If Me.Dirty Then
retval = MsgBox("Do you want to save record?", vbYesNo, "Important")

If retval = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
DoCmd.CancelEvent
End If
End If

DoCmd.Close acForm, "frmResponses", acSaveNo

End Sub




Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!company) Then
MsgBox "You must enter a company name!"
Cancel = True
DoCmd.CancelEvent
End If
End Sub



Any assistance would be greatly appreciated!

Rob
 
Try

[tt]me.undo[/tt]

in stead of the cancel thingie in the close button event.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top