Cancel button question

T

Tony Williams

I have a number of forms with a cancel button. If the user clicks on the
cancel button they get a standard Access message box. I want the use to see
a box that says "You haven't changed anything? There is nothing to cancel.
Did you mean to Close the form? If so click Yes"
And the message box would have yes/ no buttons. The creation of the message
box is OK I can do that but how do intercept the Access message box and what
code do I need to use to check whether anything has changed?
Thanks
Tony
 
D

Douglas J Steele

Check whether the form's Dirty property is set to True. If it isn't, they
haven't made any changes.
 
T

Tony Williams

Thanks Douglas. is that as simple as
"If Me.Dirty = True Then Magbee"
Will this intercept the Access message?
Thanks
Tony
 
D

Douglas J Steele

What's your code for cancelling look like?

Did you try to see whether it works?
 
T

Tony Williams

Douglas I've used this code and it seems to work OK

Private Sub cmdcancel_Click()
Dim strMsg As String

On Error GoTo Err_cmdcancel_Click
strMsg = "You haven't changed any data. Do want to close the form"

If Me.Dirty = False Then
If MsgBox(strMsg, vbQuestion + vbYesNo, "Close form?") = vbYes Then
DoCmd.Close
End If
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
Exit_cmdcancel_Click:
Exit Sub

Err_cmdcancel_Click:
MsgBox Err.Description
Resume Exit_cmdcancel_Click

End Sub

Can you see anything I might change?
Thanks
Tony
 
D

Douglas J Steele

I'm not a big fan of using MenuItems in code.

You could try replacing

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

with

Me.Undo
 
T

Tony Williams

Ok Douglas I live and learn
Tony
Douglas J Steele said:
I'm not a big fan of using MenuItems in code.

You could try replacing

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

with

Me.Undo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top