Raise Error??????

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I'm trying to raise an error if the user tries to enter certain values.
I display a msgbox first saying you can't enter this information and then
use err.raise xxx
on error resume next.
What I want to do is display the msg and then force the user to enter a
different value. Right now it displays the msg but accepts the record too.
 
AccessDeveloper said:
Hello,

I'm trying to raise an error if the user tries to enter certain
values.
I display a msgbox first saying you can't enter this information and
then use err.raise xxx
on error resume next.
What I want to do is display the msg and then force the user to enter
a different value. Right now it displays the msg but accepts the
record too.

Where are you running your code? Normally you would do a validation
like this in a BeforeUpdate event -- either of a control or of the form
itself, depending on the circumstances -- and would set the Cancel
argument of the event procedure to True if you need to prevent the
update from occurring.
 
Yes , I'm running it in a BeforeUpdate event.
Private Sub EmployeeCombo_BeforeUpdate(Cancel As Integer)
How do I set it to True?
 
Never mind! I figured it out! Thank you!

Dirk Goldgar said:
Where are you running your code? Normally you would do a validation
like this in a BeforeUpdate event -- either of a control or of the form
itself, depending on the circumstances -- and would set the Cancel
argument of the event procedure to True if you need to prevent the
update from occurring.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
AccessDeveloper said:
Yes , I'm running it in a BeforeUpdate event.
Private Sub EmployeeCombo_BeforeUpdate(Cancel As Integer)
How do I set it to True?

'----- start of example code -----
Private Sub EmployeeCombo_BeforeUpdate(Cancel As Integer)

If <your conditions> Then

' oops, this is no good.

MsgBox "Sorry, you've entered an invalid value. " & _
"Please try again."

Cancel = True

End If

End Sub
'----- end of example code -----

Of course, if the control in question is a combo box, you have the
alternative of setting the combo's LimitToList property to Yes, and then
(if you want) displaying a custom error message in the NotInList event.
 
Back
Top