Cancelling a New Record

  • Thread starter Thread starter David
  • Start date Start date
D

David

I am trying to find a way to cancel the record and close
a form without getting message that pop up from requiring
entries in certain fields. The form has about 30 fields
so I was hoping there was a way to undo any changes on
the form without having to do the

me.control.undo

for every entry. Is there a way to cancel any changes on
the entire from for the new record and allow the form to
close with no error messages.
 
David,

Hope this helps...

Private Sub BtnClear_Click()
On Error GoTo Err_BtnClear_Click

'Setup variables for Message Box and user's response
Dim MsgAnswer As Integer
Dim MsgText As String
Dim MsgStyle As Integer
Dim MsgTitle As String

MsgText = "Are You Sure You Want To Undo?"
MsgTitle = "Confirm Undo"
MsgStyle = vbYesNo + vbQuestion + vbDefaultButton2

' Confirm Clearing of fields
If Me.Dirty Then
MsgAnswer = MsgBox(MsgText, MsgStyle, MsgTitle)
If MsgAnswer = vbNo Then 'If NO do nothing
Exit Sub
Else
' If YES Undo Box Creation
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
End If

Exit_BtnClear_Click:
'For Exiting the routine
Exit Sub

Err_BtnClear_Click:

'This sections handles the situations where there is nothing to be
UNDONE

Dim MsgAnswer2 As Integer
Dim MsgText2 As String
Dim MsgStyle2 As Integer
Dim MsgTitle2 As String

MsgText2 = "There Is Nothing To Undo."
MsgStyle2 = vbOKOnly + vbExclamation + vbDefaultButton1
MsgTitle2 = "Confirm Undo - Can't Undo"

MsgAnswer2 = MsgBox(MsgText, MsgStyle, MsgTitle)
If MsgAnswer2 = vbOK Then
Resume Exit_BtnClear_Click
End If

End Sub

Sean
 
Thanks.

-----Original Message-----
David,

Hope this helps...

Private Sub BtnClear_Click()
On Error GoTo Err_BtnClear_Click

'Setup variables for Message Box and user's response
Dim MsgAnswer As Integer
Dim MsgText As String
Dim MsgStyle As Integer
Dim MsgTitle As String

MsgText = "Are You Sure You Want To Undo?"
MsgTitle = "Confirm Undo"
MsgStyle = vbYesNo + vbQuestion + vbDefaultButton2

' Confirm Clearing of fields
If Me.Dirty Then
MsgAnswer = MsgBox(MsgText, MsgStyle, MsgTitle)
If MsgAnswer = vbNo Then 'If NO do nothing
Exit Sub
Else
' If YES Undo Box Creation
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
End If

Exit_BtnClear_Click:
'For Exiting the routine
Exit Sub

Err_BtnClear_Click:

'This sections handles the situations where there is nothing to be
UNDONE

Dim MsgAnswer2 As Integer
Dim MsgText2 As String
Dim MsgStyle2 As Integer
Dim MsgTitle2 As String

MsgText2 = "There Is Nothing To Undo."
MsgStyle2 = vbOKOnly + vbExclamation + vbDefaultButton1
MsgTitle2 = "Confirm Undo - Can't Undo"

MsgAnswer2 = MsgBox(MsgText, MsgStyle, MsgTitle)
If MsgAnswer2 = vbOK Then
Resume Exit_BtnClear_Click
End If

End Sub

Sean
---------------------------------------------------------- ------------------
-----------------------------------




.
 
Back
Top