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!

How to prevent the data being saved

Status
Not open for further replies.

alvintse

Programmer
Aug 1, 2003
66
US
Hi, I am new to Access. When I created a form, it will display record by record. If I made any changes for that record, the data will save as soon as I move on to next record? Is there any way to make the form pop up a message to confirm whether to save the changes or not when I move on the next record?

Thanks.
 
The before update event of the form fires whenever an attempt to save is performed (as is the case when moving to the next record when there's unsaved changes in the current record)

If the issue is just to pop up a message box, and allow changes or not, perhaps something like this in the before update event of the form:

[tt]if msgbox("save",vbyesno)=vbNo then
me.undo
end if[/tt]

Roy-Vidar
 
Even simpler, just paste this code into your form's code module:
Code:
[COLOR=blue]Private Sub[/color] Form_BeforeUpdate(Cancel [COLOR=blue]As Integer[/color])
    Cancel = (MsgBox("Save changes?", vbQuestion + vbYesNo) = vbNo)
[COLOR=blue]End Sub[/color]
 
Thanks for your prompt suggestion. I have taken both method and come up with:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Save changes?", vbYesNo) = vbNo Then
Me.Undo
End If
End Sub

Thanks
 
So, where should I put this code in order to apply for all forms?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top