View Full Version : Getting rid of error


LaurieW
04-14-2003, 09:45 AM
I have this code on my form's BeforeUpdate event. It is checking to make sure 2 required fields are filled before saving:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Status) Then
MsgBox "Status is required; please select a Status from the list.", vbExclamation, "Terminations Data Entry"
Status.SetFocus 'place cursor in Status field
Cancel = True 'cancels saving the record
ElseIf IsNull(StatusDate) Then
MsgBox "Status Date is required; please enter Status Date", vbExclamation, "Terminations Data Entry"
StatusDate.SetFocus 'place cursor in Status Date field
Cancel = True 'cancels saving the record
End If
End Sub

The message boxes come up just fine, but then I also am receiving this error:

"The DoMenuItem action was canceled."

How do I get rid of this error showing up? I've tried lots of things but am stuck.

Thanks for your assistance.

directormac
04-14-2003, 09:51 AM
You can set warnings to off just before your cancel statement and set them back to on just after. Check Access help for "setwarning"

Caveat Emptor: Always be careful to turn your warnings back on!

--Latin Mac

LaurieW
04-14-2003, 10:01 AM
I already tried the "DoCmd.SetWarnings False" and it doesn't work. I still keep getting this "The DoMenuItem Action was canceled" error box after my message box closes.

Any other ideas?

directormac
04-14-2003, 10:26 AM
Two things:

(1) You might try putting your checking code into the individual BeforeUpdate events of the respective controls rather than the form. Just a thought.

(2) Add an undo into your code. See this thread (http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=27300), among others (search the forum on "cancel and save and message").

--Grasping Mac