Cancel a New Record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form on which I have a command button to add a new record. If a user
is in the middle of adding a record and decides not to pursue the new record,
how do I code to allow the user to dump the record without having to hit
escape? Perhaps a command button that says "cancel new record"...I wouldn't
want this button to delete any other records as the users are not allowed to
delete other records from this database. Thanks in advance.
 
Folks I was able to figure this out. I used the undo command and incorporated
the code from undo into my cancel record button. I then added code to go the
first record on error because if the user pressed the cancel record button
but had not yet entered a field into a new record I got a message that the
undo wasn't available. With the collaboration fo these things, the button
does exactly what I want it to. Thank you.
 
Folks, this achieved my results. I took code from the undo button and I had
to add the code on error to take the user back to the first record as if the
user pressed the cancel button before putting in a field of a new record, the
user got an error that the undo feature was not available.

Thanks for your help.

Private Sub cmdDump_Click()
On Error GoTo Err_cmdDump_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.GoToRecord , , acFirst

Exit_cmdDump_Click:
Exit Sub

Err_cmdDump_Click:
DoCmd.GoToRecord , , acFirst
Resume Exit_cmdDump_Click

End Sub
 
Folks, this achieved my results. I took code from the undo button and I had
to add the code on error to take the user back to the first record as if the
user pressed the cancel button before putting in a field of a new record, the
user got an error that the undo feature was not available.

Thanks for your help.

Private Sub cmdDump_Click()
On Error GoTo Err_cmdDump_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.GoToRecord , , acFirst

Exit_cmdDump_Click:
Exit Sub

Err_cmdDump_Click:
DoCmd.GoToRecord , , acFirst
Resume Exit_cmdDump_Click

End Sub
 
Buttons are a bit of a crutch, it's easy to get a form covered in them
but they are not very user-friendly. If the user is doing data entry
a button requires them to stop and use the mouse. We try to do it all
with code.

In this case, I would create a dialog box that pops up and asks the
user to confirm the entry with an OK/Cancel option. Try something
like this
----------- Code Start -----------------
Private Sub frmMyForm_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_frmMyForm_Click

Dim Msg, Style, Title

' Define message......................
Msg = "Is this record complete for saving?" _
& vbCrLf & vbCr & "If the change is correct, press OK" _
& vbCrLf & vbCr & "If this is a mistake, press Cancel to undo
the change"

' Define buttons......................
Style = vbOKCancel + vbCritical + vbDefaultButton2
' Define title..........................
Title = "Confirm Save Record?"


Response = MsgBox(Msg, Style, Title)

If Response = vbOK Then '.......... User chose Yes.
GoTo ProceedWithUpdate '...........complete the change

Else '.......... User chose No.
Me.Undo '.......... Undo the change.

End If


ProceedWithUpdate:
Exit Sub

Err_frmMyForm_Click:
MsgBox Err.Description
Resume ProceedWithUpdate

End Sub
----------- Code End -------------------

Brett

I have a form on which I have a command button to add a new record. If a user
is in the middle of adding a record and decides not to pursue the new record,
how do I code to allow the user to dump the record without having to hit
escape? Perhaps a command button that says "cancel new record"...I wouldn't
want this button to delete any other records as the users are not allowed to
delete other records from this database. Thanks in advance.

Cheers,
Brett
 
Back
Top