Code ain't pretty

  • Thread starter Thread starter Stephanie
  • Start date Start date
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
 
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.
 
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
 
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.
 
Back
Top