Validate textbox's with Form BeforeUdate

  • Thread starter Thread starter Neal Ostrander
  • Start date Start date
N

Neal Ostrander

I want to check the values in 5 textbox's on a form if the contain any number
other than 0 I want to check a 6th textbox to make sure its value is greater
than 0 also. I figured the form's BeforeUpdate would be the best place to do
this check but I am not quite sure how to set up the code to accomplish this
task.
Thanks for any help
Neal
 
Example code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Textbox1.Value = 0 Then
Cancel = True
Me.Textbox1.SetFocus
MsgBox "Cannot have a 0 value in textbox1", vbOK, _
"Zero Not Allowed"
ElseIf Me.Textbox2.Value = 0 Then
Cancel = True
Me.Textbox2.SetFocus
MsgBox "Cannot have a 0 value in textbox2", vbOK, _
"Zero Not Allowed"
ElseIf Me.Textbox3.Value = 0 Then
Cancel = True
Me.Textbox3.SetFocus
MsgBox "Cannot have a 0 value in textbox3", vbOK, _
"Zero Not Allowed"
' continue with more ElseIf blocks as needed
End If
 
Back
Top