Closing form without changes

  • Thread starter Thread starter gb
  • Start date Start date
G

gb

Hello

I use a subform on my main form and can double-click an entry within it to
view all of the information in that record in a separate form that pops up.

If a user edits the information in this new form, a button is supplied to
save and close the record.

I would like a button that closes the form without saving any changes made,
too. I have found that a button that just closes the form (DoCmd.Close)
saves the record nonetheless.

How do I get the code to check whether any changes were made, and if so, to
discard them and close the form?

Thank you for your help

gb
 
Hello

I use a subform on my main form and can double-click an entry within it to
view all of the information in that record in a separate form that pops up.

If a user edits the information in this new form, a button is supplied to
save and close the record.

I would like a button that closes the form without saving any changes made,
too. I have found that a button that just closes the form (DoCmd.Close)
saves the record nonetheless.

How do I get the code to check whether any changes were made, and if so, to
discard them and close the form?

Thank you for your help

gb

If Me.Dirty Then
If MsgBox ("Save changes?", vbYesNo) = vbNo Then
Me.Undo
Else
Me.Dirty = False
End If
End If

- Jim
 
gb said:
Hello

I use a subform on my main form and can double-click an entry within it to
view all of the information in that record in a separate form that pops up.

If a user edits the information in this new form, a button is supplied to
save and close the record.

I would like a button that closes the form without saving any changes made,
too. I have found that a button that just closes the form (DoCmd.Close)
saves the record nonetheless.

How do I get the code to check whether any changes were made, and if so, to
discard them and close the form?

Thank you for your help

gb


You need to use a BeforeUpdate Form Event's.
Inside it you can ask with Message Box if the user
want to Save changes if made.
This Event occour if the user make changes.

Try with this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
strMsg as Satring
strMsg=MsgBox("Save changes..?",vbYesNo+VbQuestion,"Attention")
If strmsg=vbNo then
Me.Undo
Cancel=True
End if
End Sub

Bye.
 
Back
Top