If..Then..Else statement not working for Ye/No ComboBox?

  • Thread starter Thread starter mezzanine1974
  • Start date Start date
M

mezzanine1974

Say that we have a ComboBox1 where its value are either YES or NO.
I am writing such a simple If..Then..Else statement but it is not
responding properly.

If Me.ComboBox1.Value = Yes Then
...Statement1
ElseIf Me.ComboBox1.Value = No then
...Statement2
EndIf

As for above code, when combo value is NO, Statement1 is executed,
instead Statement2. When combo value is YES, nothing is executed!

I could not sleep yesterday night because of this mystery. Could you
help me please.

Thanks
 
Assuming that you've got the words Yes and No in the combo box, try putting
quotes in your If statement:

If Me.ComboBox1.Value = "Yes" Then
..Statement1
ElseIf Me.ComboBox1.Value = "No" then
..Statement2
EndIf
 
I already tried "Yes" and "No" style before asking this question. In
that way, action is not responding in any way.
It is interesting that this type of Conditional Statement is not
responding properly only if its data type YES/NO
 
Are you saying that you're actually displaying a Boolean data field (the
real name for a Yes/No field: I've never figured out why Microsoft used that
alias)?

Try

If Me.ComboBox1.Value = True Then
..Statement1
ElseIf Me.ComboBox1.Value = False then
..Statement2
EndIf
 
Hello Dougles,
I have tried many ways. I tested this phenomonia on a form. I placed a
ComboBox on that form and set the data type (YES/NO, TRUE/FALSE, ON/
OFF) respectively. In any type of those, this conditional statement is
not working.
OnClick event of Details of the form, I write such code.

Private Sub Detail_Click()
If Me.Combo0.Value = // {YES, "YES", TRUE, "TRUE", ON, "ON"} // Then
Me.Combo0.Left = 4
ElseIf Me.Combo0.Value = {NO, "NO", FALSE, "FALSE", OFF, "OFF"} Then
Me.Combo0.Left = 6
End If
End Sub

I tried all configuratios above. My target was to check if ComboBox1
is moving accordingly. I could not find a way whole night to achive
that!
 
This is the answer !! I found it.. Thanks

If Me.ComboBox1.Value = -1 Then
..Statement1
ElseIf Me.ComboBox1.Value = 0 then
..Statement2
EndIf
 
Glad you got it solved, but that makes no sense at all!

True (no quotes) evaluates to -1, while False (no quotes) evaluates to 0, so
the following should be identical to your solution:

If Me.ComboBox1.Value = True Then
..Statement1
ElseIf Me.ComboBox1.Value = False then
..Statement2
EndIf
 
Back
Top