Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF statement not working correctly 4

Status
Not open for further replies.

SeadnaS

Programmer
May 30, 2011
214
I've done something wrong here it seems. The following code is giving me all "FAIL" results even when it should be "PASS". I want my subform to display pass/fail results in the column next to the x1 number but this code is only showing fail. What could be causing this?

Private Sub x1_Change()
If Me.Parent.TESTS.Value = 1 Then
If x1 >= Me.Parent.SPEC1.Value Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

If Me.Parent.TESTS.Value = 2 Then
If x1 <= 20 Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

If Me.Parent.TESTS.Value = 3 Then
Me.passfail.Value = "N/A"
End If
If Me.Parent.TESTS.Value = 4 Then
If (x1 <= Me.Parent.bodmax And x1 >= Me.Parent.bodmin) Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

If Me.Parent.TESTS.Value = 5 Then
If (x1 <= Me.Parent.bodqmax And x1 >= Me.Parent.bodqmin) Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

If Me.Parent.TESTS.Value = 6 Then
If x1 >= 5 Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

If Me.Parent.TESTS.Value = 7 Then
If x1 >= 5 Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

If Me.Parent.TESTS.Value = 8 Then
If x1 >= 5 Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

If Me.Parent.TESTS.Value = 9 Then
If x1 >= 10 Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

If Me.Parent.TESTS.Value = 10 Then
If x1 = "Pass" Then
Me.passfail.Value = "PASS"
Else: Me.passfail.Value = "FAIL"

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
 
Need the quickest solution to this. Ok, this is what I'm using:

Dim intTests As Variant, dblSpec1 As Variant, dblX1 As Variant
intTests = Me.Parent.TESTS.Value
dblSpec1 = Me.Parent.SPEC1.Value
dblX1 = Me.x1
dblBODMAX = Me.Parent.bodmax.Value
dblBODMIN = Me.Parent.bodmin.Value
dblBODQMIN = Me.Parent.bodqmin.Value
dblBODQMAX = Me.Parent.bodqmax.Value

Select Case True
Case intTests = 1 And dblX1 >= dblSpec1
Me.passfail = "PASS"

Case intTests = 2 And dblX1 <= 20
Me.passfail = "PASS"

Case intTests = 3 And dblX1 = "Long" Or "LONG" Or "long"
Me.passfail = "PASS"

Case intTests = 3 And dblX1 <> "Long" Or "LONG" Or "long"
Me.passfail = "CHECK!"

Case intTests = 4 And dblX1 <= dblBODMAX And dblX1 >= dblBODMIN
Me.passfail = "PASS"

Case intTests = 5 And dblX1 <= dblBODQMAX And dblX1 >= dblBODQMIN
Me.passfail = "PASS"

Case intTests = 6 And dblX1 >= 5
Me.passfail = "PASS"

Case intTests = 7 And dblX1 >= 5
Me.passfail = "PASS"

Case intTests = 8 And dblX1 >= 5
Me.passfail = "PASS"

Case intTests = 9 And dblX1 >= 10
Me.passfail = "PASS"

Case intTests = 10 And dblX1 = "PASS" Or dblX1 = "Pass" Or dblX1 = "pass"
Me.passfail = "PASS"

Case Else
Me.passfail = "FAIL"

End Select

What i'm trying to do is to see if "Long", "LONG" or "long" are entered and then sending "CHECK!" instead of fail if something other than "long" etc is entered. I realise that "long" is a string but i need text in that column. How do i do this and what have i done wrong in the above code. I'm still a newbie at all of this and can't get this working!
 
Forgot to mention that i get an error "type mismatch
 
Replace this:
Case intTests = 3 And dblX1 = "Long" Or "LONG" Or "long"
with this:
Case intTests = 3 And UCase(dblX1) = "LONG"

And so on for each similar.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks thats exactly what i need!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top