Why if-then-else fails???

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.
 
A

Allen Browne

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.
 
D

Dirk Goldgar

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 & "'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top