Discussion:
case in point
(too old to reply)
Jimmy Warpup
2009-02-18 23:32:53 UTC
Permalink
can someone tell me why the following code only runs the "else" criterion?

Private Sub French_word_BeforeUpdate(Cancel As Integer)

MsgBox "begining"
'troubleshooting make sure sub is being run at right time. it does.

MsgBox IsNull(DLookup("[French_word]", "[Words]", "[French_word] = """ &
Me![French_word] & """"))
'troubleshooting to see what the line returned. if the word is in the
database then it returns false if the word is not it returns true.

Select Case Me.French_Word
Case IsNull(DLookup("[French_word]", "[Words]", "[French_word] = """ &
Me![French_word] & """")) = False
MsgBox "first case"
Exit Sub

Case IsNull(DLookup("[French_word]", "[Words]", "[French_word] = """ &
Me![French_word] & """")) = True
MsgBox "not isnul"

Case Else
MsgBox "No workie workie " & Me!French_word & " " &
DLookup("[French_word]", "[Words]", "[French_word] = """ & Me![French_word]
& """")
Exit Sub
End Select

End Sub
tina
2009-03-29 21:34:29 UTC
Permalink
well, this is an old post, so hopefully you've solved it already. but i'll
answer for anyone else who may read the post in future. you're writing the
code as though the expressions are being used in an If...Then...ElseIf...
statement, rather than Select Case.

what your code essentially says is

(Select Case) Look at the value of Me.French_Word
(Case) If that value is equal to True
(any expression with an operator evaluates to True or False)
Then run this code
MsgBox "first case"
Exit Sub

(Case) If that value is equal to True
(as noted above, any expression with an operator...)
Then run this code
MsgBox "not isnul"
(Case Else) Otherwise run this code
MsgBox "No workie workie " & Me!French_word _
& " " & DLookup("[French_word]", "[Words]", _
& "[French_word] = """ & Me![French_word] & """")
Exit Sub
End Select

i think the value of Me![French_word] is actually a word, correct? and while
you could do this with a Select Case statement, since you're just checking
for essentially a true or false condition (the word is in the table or it
isn't), i'd use If...Then...Else, as

If DCount(*, "Words", "French_word = '" _
& Me![French_word] & "'") < 1 Then
' this is the False, or not found, test
Msgbox "The word was not found."
Exit Sub
Else
Msgbox "The word was found."
End If

there's no need to test separately for "the word was found". it was either
found, or it wasn't, and there's no third option to consider - the word was
either found, or it wasn't.

hth
Post by Jimmy Warpup
can someone tell me why the following code only runs the "else" criterion?
Private Sub French_word_BeforeUpdate(Cancel As Integer)
MsgBox "begining"
'troubleshooting make sure sub is being run at right time. it does.
MsgBox IsNull(DLookup("[French_word]", "[Words]", "[French_word] = """ &
Me![French_word] & """"))
'troubleshooting to see what the line returned. if the word is in the
database then it returns false if the word is not it returns true.
Select Case Me.French_Word
Case IsNull(DLookup("[French_word]", "[Words]", "[French_word] = """ &
Me![French_word] & """")) = False
MsgBox "first case"
Exit Sub
Case IsNull(DLookup("[French_word]", "[Words]", "[French_word] = """ &
Me![French_word] & """")) = True
MsgBox "not isnul"
Case Else
MsgBox "No workie workie " & Me!French_word & " " &
DLookup("[French_word]", "[Words]", "[French_word] = """ &
Me![French_word]
Post by Jimmy Warpup
& """")
Exit Sub
End Select
End Sub
Loading...