Error Message - Do Menu Item action cancelled

G

Guest

I am trying to write code that says if Status_Code = "Inactive" and
Vendor_Nbr <> 0, then Contract_End_Date is required. I put the following at
the BeforeUpdate event and am getting a Do Menu Item cancelled error message
when I try to save the record and purposely leave out required data (from
other fields as a test) - I get the correct error message for the missing
data but keep getting this DoMenu Item action cancelled error message box
right after the first message about the missing data. Thanks for any help!

Here's the code:

If (Me.Status_Code = "Inactive" And Vendor_Nbr <> 0 And
IsNull(Me.Contract_End_Date)) Then
strMsg = strMsg & "Please enter a Contract End Date." & vbCrLf
Cancel = True
End If
 
G

Guest

I added a command button to save the record...that is what I am clicking on
when I try to save it.

I just used the wizard to make the button - the following code is on the
click event of the button:

Private Sub Command331_Click()
On Error GoTo Err_Command331_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Command331_Click:
Exit Sub

Err_Command331_Click:
MsgBox Err.Description
Resume Exit_Command331_Click

End Sub
 
A

Allen Browne

So, the 2nd message is notifying you that the attempt to save the record
(using DoMenuItem) did not succeed?

Change the line:
MsgBox Err.Description
to:
MsgBox "Error " & Err.Number & " - " & Err.Description

When it fails, write down the 4-digit number. Then go back and change the
line to:
If Err.Number <> xxxx Then MsgBox Err.Description
plugging the number in place of the xxxx.
 
G

Guest

Thanks for the help! It worked great. Lori

Allen Browne said:
So, the 2nd message is notifying you that the attempt to save the record
(using DoMenuItem) did not succeed?

Change the line:
MsgBox Err.Description
to:
MsgBox "Error " & Err.Number & " - " & Err.Description

When it fails, write down the 4-digit number. Then go back and change the
line to:
If Err.Number <> xxxx Then MsgBox Err.Description
plugging the number in place of the xxxx.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top