Why if-then-else fails???

  • Thread starter Thread starter Steve S
  • Start date Start date
S

Steve S

What seemed to be a fairly straight forward if-then-else has really got me
down in the dirt. If 1303 = 1303 going into the if-then-else why is it true
if testing for 1303 <> 1303 ???
the code is:

Debug.Print Nz(DLookup("Judge", "qryMaxJudges", "Judge=" & Me.ComboJudges),
0) & " = " & Me.Combo_Judges

displays: 1303 = 1303

MsgBox Nz(DLookup("Judge", "qryMaxJudges", "Judge=" & Me.ComboJudges), 0) &
" = " & Me.ComboJudges

displays: 1303 = 1303

But then the test indicates that is not true

If Nz(DLookup("Judge", "qrymaxjudges", "Judge=" & Me.ComboJudges), 0) <>
Me.Combo_Judges Then

MsgBox Nz(DLookup("Judge", "qrymaxjudges", "Judge=" & Me.ComboJudges), 0) &
" <> " & Me.ComboJudges

displays: 1303 <> 1303

Debug.Print Nz(DLookup("Judge", "qrymaxjudges", "Judge=" & Me.ComboJudges),
0) & " <> " & Me.ComboJudges

displays: 1303 <> 1303

Exit Sub
End If

Any and all help is appreciated.
 
Steve, this might be about data types.

Try:
Debug.Print TypeName(Me.Combo_Judges.Value)
Debug.Print TypeName(DLookup("Judge", "qryMaxJudges")

If they are different data types, you may need to use Val() or CLng() or
something to get them to match.

Alternatively, see what happens if you subtract them.
 
Steve S said:
What seemed to be a fairly straight forward if-then-else has really got me
down in the dirt. If 1303 = 1303 going into the if-then-else why is it
true
if testing for 1303 <> 1303 ???
the code is:

Debug.Print Nz(DLookup("Judge", "qryMaxJudges", "Judge=" &
Me.ComboJudges),
0) & " = " & Me.Combo_Judges

displays: 1303 = 1303

MsgBox Nz(DLookup("Judge", "qryMaxJudges", "Judge=" & Me.ComboJudges), 0)
&
" = " & Me.ComboJudges

displays: 1303 = 1303

But then the test indicates that is not true

If Nz(DLookup("Judge", "qrymaxjudges", "Judge=" & Me.ComboJudges), 0) <>
Me.Combo_Judges Then

MsgBox Nz(DLookup("Judge", "qrymaxjudges", "Judge=" & Me.ComboJudges), 0)
&
" <> " & Me.ComboJudges

displays: 1303 <> 1303

Debug.Print Nz(DLookup("Judge", "qrymaxjudges", "Judge=" &
Me.ComboJudges),
0) & " <> " & Me.ComboJudges

displays: 1303 <> 1303

Exit Sub
End If

Any and all help is appreciated.


Hmm, it's certainly not obvious. Try a little investigation of the data
types of the two values, and also check for leading or trailing spaces in
them:

Debug.Print TypeName(Nz(DLookup("Judge", "qryMaxJudges", "Judge=" &
Me.ComboJudges), 0))

Debug.Print TypeName(Me.ComboJudges.Value)

Debug.Print "'" & Nz(DLookup("Judge", "qryMaxJudges", "Judge=" &
Me.ComboJudges), 0) & "'"

Debug.Print "'" & Me.ComboJudges & "'"
 
Back
Top