By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,499 Members | 829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,499 IT Pros & Developers. It's quick & easy.

Prevent DoCmd Cancel Message From Appearing

P: n/a
Although I have used the code below to suppress the DoCmd cancel
action message from appearing on lots of other actions such as preview
and print, I have not been able to get to work on a BeforeUpdate Event
Procedure. There is nothing elaborate about the event, however, there
is an initial message box stating that if one field contains data then
a second one must also, and then after clicking okay, the
DoCmdMenuItem action box is displayed.

Any suggestions on addressing this problem will be appreciated.
Thanks.
Private Sub Form_BeforeUpdate (Cancel As Integer)
Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:

Const conErrDoCmdCancelled = 2501
If (err = conErrDoCmdCancelled) Then
Resume Exit_Form_BeforeUpdate
Else
MsgBox err.description
Resume Exit_Form_BeforeUpdate
End If

End Sub
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Dalan wrote:
Although I have used the code below to suppress the DoCmd cancel
action message from appearing on lots of other actions such as preview
and print, I have not been able to get to work on a BeforeUpdate Event
Procedure. There is nothing elaborate about the event, however, there
is an initial message box stating that if one field contains data then
a second one must also, and then after clicking okay, the
DoCmdMenuItem action box is displayed.

Any suggestions on addressing this problem will be appreciated.
Thanks.

Private Sub Form_BeforeUpdate (Cancel As Integer)

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:

Const conErrDoCmdCancelled = 2501
If (err = conErrDoCmdCancelled) Then
Resume Exit_Form_BeforeUpdate
Else
MsgBox err.description
Resume Exit_Form_BeforeUpdate
End If

End Sub


What are you ":canceling" in the before update event? Are you calling a
routine that recalls the BeforeUpdate event? Cancel is used to inform
Access whether or not the record can be saved.

Here is some example code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On error GoTo Err_Routine

'assume the save operation will fail validation checks
Cancel = True
If IsNull(Me.Field1) then
msgbox "Field1 is required."
me.field1.setfocus
Elseif Me.Field2 <> 1 and Me.Field2 <> 2 then
msgbox "Field2 must be a 1 or 2
me.field2.setfocus
elseif Msgbox("Are you sure you want to save
changes?",vbYesNo,"ConfirmChanges) = vbYes then
'validation checks passes and user confirmed save
Cancel = False
endif

Exit_Routine:
Exit Sub

Err_routine
msgbox Err.description
Resume Exit_Routine
End Sub
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.