cancel entire acNewRec and go back to Form Load state

Rx_

Nothing In Moderation
Local time
Today, 12:36
Joined
Oct 22, 2009
Messages
2,803
Trying to fix something quick for someone.
The Add New button uses : DoCmd.GoToRecord , , acNewRec
If a specific condition happens - how to totally cancel the new record - then call Sub Form_Load() that resets form back to desired state (before the Add New)?

There are 10 required fields that are enabled - must be completed before the record is written - then the rest of the non-required fields are enabled. The required fields use:
Dim bSomethingIsMissing As Boolean

bSomethingIsMissing = False
If IsNull(Me.cboReq_Fin) Then
bSomethingIsMissing = True
End If
If IsNull(Me.cboDescSHLBHL) Then
bSomethingIsMissing = True
End If ' eight more fields checked like this then ...
If bSomethingIsMissing Then
Cancel = True

There are a lot of flags set along the way.
The Form Load can't be called from within the Form_BeforeUpdate(Cancel As Integer). It generates an error.
Want to do more than undo the last field entry. Want to undo the entire ACAddNew. Then reset the entire form per the various code in the Form Load event.

The Cancel = True sill requires the user to eventually complete the required 10 fields.
 
Me.Undo will reset the entire form.

in the Form's UNDO event you may be able to call the Load. But you may want to move that code to a procedure within the form and then be able to call it from both the load event and the undo event. That would be my preference.
 
Worked like a champ!

e.g.
' continued from code in first post
' ... multiple rule function to determine if business rule was violated
Msgbox "This combination violates the business rules, please read the C.R.C pages 11-23-245 through 11-23-1342 and try again", vbOkOnly, "Regulatory Submission Not Allowed per C.R.C."
Answer = MsgBox("cancel the Add New", vbYesNo, "Violation in Form Before Update")
If Answer = vbYes Then
TotalRecall3
End If
' .......... the solution - end the Form_beforeUpdate and call the procedure
Sub TotalRecall3()
Me.Undo
Form_Load
End Sub
 

Users who are viewing this thread

Back
Top Bottom