Closing form and saving data

  • Thread starter Thread starter Delf
  • Start date Start date
D

Delf

Each time I clik on the close button the data get
automatically saved. How can I change this so if by
mistake I have pressed a button in a box, when closing it
asks me if I want to save the changes and if I press "No"
it doesn't change anything but keeps the original info?

Thanks.
Delf
 
Use the Form_BeforeUpdate Event to display a MsgBox asking
whether the Edit should be save or not. Something like

****Untested****
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim intResponse As Integer

intResponse = MsgBox("Save Record?", vbYesNoCancel)

Select Case intResponse
Case vbYes
'Do Nothing
Case vbNo
Me.Undo 'To undo the edit
Case vbCancel
Cancel = True 'To cancel the update & hence the close
End Select

End Sub
********

HTH
Van T. Dinh
MVP (Access)
 
thanks heaps Van.
Now on my form I have subforms how do I get them as well
to do this as for now everytime I click in a subfrm it
asks me automatically if I want to change the details. I
want it to say this only when I close the main form, not
everytime I change something on subfrm.
Tx
 
On bound Form / Subform set-up (which you should have mentioned in your
original post), there is the AutoSave feature that automatically tries to
update the Record in the main Form into the Table as soon as you move the
Focus from the main Form to the Subform. Similar, the Records in the
Subform will be updated into the Table automatically as soon as you move the
Focus from the Subform to the main Form.

This is to preserve the R.I. of the Parent - Child Records that the Form /
Subform combination usually handles.

You cannot disable the AutoSave feature. My work-around is to hide the
Subform and force the user to save the Record on the main Form (by clicking
a Save CommandButton on the main Form) before the Subform is displayed.
 
Back
Top