Re: Validate textbox's with Form BeforeUdate

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


"Neal Ostrander" <NealOstrander@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2CC6DFD5-474D-4E60-BB2D-4B8A414ADB4B@xxxxxxxxxxxxxxxx
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


.



Relevant Pages

  • Re: Validate 3 Text Fields - Urgent Need to finish by Monday
    ... Cancel = True in the code does absolutely nothing. ... Private Sub Box236_Click ... ElseIf IsNullThen ... MsgBox "You must select a Location" ...
    (microsoft.public.access.formscoding)
  • Re: Must enter something in a field
    ... Private Sub REASON1_BeforeUpdate ... Cancel = True ... MsgBox "Value cannot equal 0!" ... ElseIf Me.REASON1_SomeValue 0 Then ...
    (microsoft.public.access.queries)
  • Re: Must enter something in a field
    ... Private Sub REASON1_BeforeUpdate ... Cancel = True ... MsgBox "Value cannot equal 0!" ... ElseIf Me.REASON1_SomeValue 0 Then ...
    (microsoft.public.access.queries)
  • Re: if then else
    ... Private Sub FindRecord_BeforeUpdate ... ElseIf rs.NoMatch Then ... Cancel = True ... gone straight to msgbox but I get a similar error message. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Question on pole-zero cancellation
    ... The numerator includes a zero at DC, the denominator gives a pole at DC, ... and so these cancel, ... Pole-zero cancellations work if the mathematics is exact. ...
    (comp.dsp)