difference in code? in validation field

  • Thread starter Thread starter Tim Schiermeyer
  • Start date Start date
T

Tim Schiermeyer

Can anyone tell me the difference between these two lines of code. I have
them place in the validation box for a check box control. One works
perfectly, the other allows for the selection of the check box but not the
deselection.

Line 1. =IIf(InStr([Rating_Errors_Full],"R6")>0,-1,0)
Or IIf(InStr([Rating_Errors_Full],"R6")>0,0,0)
And IIf([E_MVA]>0,0,0) Or IIf([E_MVA]>0,-1,0)

Line 2. =(IIf(InStr([Rating_Errors_Full],"R6")>0,-1,0)
Or IIf(InStr([Rating_Errors_Full],"R6")>0,0,0))
And (IIf([E_MVA]>0,0,0) Or IIf([E_MVA]>0,-1,0))

Note: only difference is the () used for grouping the logic in line 2. Line
1 is the item that performs correctly.
Thanks
Tim Schiermeyer
 
Just found error in line 1 below, this works for the determining if there is
a zero value in a field but bypasses the first validation. Is there an
alternative to those strings to evaluate the two criteria?
Thanks
Tim
 
I would consider using the before update event of the check box.

You can write nice code, and it is far easier to read then a difficult multi
complex iff statement.

Your code could be:

Private Sub Check14_BeforeUpdate(Cancel As Integer)

Dim bolCh1 As Boolean
Dim bolch2 As Boolean

bolCh1 = InStr([Rating_Errors_Full], "R6") > 0
bolch2 = e_mva > 0

If bolCh1 Or bolch2 Then
Cancel = True
msgbox "you must select MVA"
End If

End Sub

The above also lets you customize your error message:

You can even go:

if e_mva = false then
cancel = true
msgbox "you must first select mva"
endif

The above is just some examples, but the idea here is to test the fields,
and then set cancel to true if you want to user to "fix" the field.
 
Back
Top