Cancel event is saving the record, anyway.

ahvc

Registered User.
Local time
Today, 05:28
Joined
Jun 17, 2002
Messages
41
Hello,

I am using the Docmd command to close a form. I use this in the cancel button for the form. I hoped that the following line will do it, without saving the information. But it does save the record changes anyway.

DoCmd.Close acForm, "frmDailyLog", acSaveNo


I would like to avoid it, since the save button also saves it, I want the cancel button not to save the record. Can anyone pl tell what I am missing.

Thanks
VC
 
Search the forums here (for instance the Forms forum on "canvel record").
Or create a "cancel" button in your form.
Open your form in design mode, "define a button using the wizard.


RV
 
I think you may find that it is the order you have written this

Place the SaveNo, before the close form, at the moment, to me it looks as though you are closing the form then once it is closed it no longer has a record to 'not save', I think by swapping this around it should help you
 
try:

Private Sub btnCancel_Click()

Dim ctl as Control

'checks if record changes after last save
If Me.Dirty Then
'restore all controls (NOTE: types could be added)
For Each ctl in Me.Controls
If TypeOf ctl is acTextBox or TypeOf ctl is acComboBox Then
'restore to old value
ctl.Value = ctl.OldValue
End If
Next ctl
End If

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
 
it worked.. thanks ...

Dear guys
It worked.. thank you so much.. I really mean it.. it made life much easier for me today..

regards
vc
 
that was a useful lesson, Thank you Pat.
 

Users who are viewing this thread

Back
Top Bottom