Code ain't pretty

S

Stephanie

Hi. I am trying to streamline code based on MVP
suggestions. I added "exit sub" so that each condition
will be judged on it's own merits (see snippet below), but
now after clicking "OK", I'm getting notification: "The
DoMenuItem action was canceled". What's that all about?
Is exit sub not the way to go? Thanks, Stephanie

If IsNull(Me!MemberDateName) And (Not IsNull(Option1) Or
Not IsNull(Option2)) Then
iAns = MsgBox("Please enter an 'Associated Since' Date
to continue, or click Cancel to erase this record",
vbOKCancel)
If iAns = vbOK Then
Cancel = True
Me!MemberDateName.SetFocus
Else
Cancel = True
Me.Undo ' erase the entire form
End If
Exit Sub
End If
 
K

Ken Snell [MVP]

The Cancel = True step is what's giving rise to the error message that you
get. When you cancel an event, an error is returned to the code that gave
rise to that event. You'll need to trap for the error in the calling code.
 
G

Guest

Thanks, Ken. I don't understand "trap for the error in
the calling code". I'm a coding light-weight. Could you
show me how to "trap"? Thanks, Stephanie
 
K

Ken Snell [MVP]

You'll need to post all the code that you're using -- the code that calls
the code snippet that you posted, and the code that contains the code
snippet that you posted.
 

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

Similar Threads


Top