Validation of a field

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

Guest

Hallo

I have a button on my form and when I click on it I would like it to
validate a few fields before going to the next record or closing the form

For an example I have a field prize and I would like to validate it if the
prize is bigger then 0 before closing or going to the next record.

If some one could give me the code

Thank you

Markus
 
Put some code into your form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If myPrizeField < 0 Then
MsgBox "Incorrect Prize!"
Cancel = True
End If
End Sub
 
Hallo

Thank you for the code it works fine just the only thing that not right is
when the prize is 0 it will give me the message box and then close the form
when I click on my close button but what I want it to do then if the prize is
0 then it should give me the error message and not close the form and got to
the prize field so I can correct my mistake.

Markus
 
Just use Prize<=0
HTH
-----Original Message-----
Hallo

Thank you for the code it works fine just the only thing that not right is
when the prize is 0 it will give me the message box and then close the form
when I click on my close button but what I want it to do then if the prize is
0 then it should give me the error message and not close the form and got to
the prize field so I can correct my mistake.

Markus


.
 
Back
Top