If vs If Not (One works the other doesn't)

Vonik

Registered User.
Local time
Today, 11:18
Joined
Mar 17, 2014
Messages
17
Why don't both of these pieces of code work, when I enter No into the combo box? :banghead:

This code works.
Code:
If Me.ComboBillable = "Yes" Or Me.ComboBillable = "No" Then
Else
    MsgBox "You must choose an Appropriate Billing Option"
    Me.ComboBillable.BorderColor = RGB(255, 0, 0)
    Me.ComboBillable.SetFocus
    Exit Sub
End If

This code doesn't work.
Code:
If Not Me.ComboBillable = "Yes" Or Me.ComboBillable = "No" Then
    MsgBox "You must choose an Appropriate Billing Option"
    Me.ComboBillable.BorderColor = RGB(255, 0, 0)
    Me.ComboBillable.SetFocus
    Exit Sub
End If

Any help is greatly appreciated. Thanks.
 
The Not applies only to the first check.

Code:
If Me.ComboBillable <> "Yes" And Me.ComboBillable <> "No" Then

Or:

Code:
If IsNull(Me.ComboBillable) Then
 
Try

If Me.ComboBillable <> "Yes" And Me.ComboBillable <> "No" Then
 
Or:
Code:
If Not (Me.ComboBillable = "Yes" Or Me.ComboBillable = "No") Then
... but is this a Yes/No field? If it is then the Yes and No should be written without the quotes.
 
The Not applies only to the first check.

Thanks, I figured it was something like that; however, this doesn't work either.

Code:
If Me.ComboBillable <> "Yes" Or Me.ComboBillable <> "No" Then
    MsgBox "You must choose an Appropriate Billing Option"
    Me.ComboBillable.BorderColor = RGB(255, 0, 0)
    Me.ComboBillable.SetFocus
    Exit Sub

Doesn't work either is it because Yes and No are text strings?
 
... but is this a Yes/No field? If it is then the Yes and No should be written without the quotes.

Did you miss the fact that the first version works, with quotes? ;)
 
Thanks, I figured it was something like that; however, this doesn't work either.

Code:
If Me.ComboBillable <> "Yes" Or Me.ComboBillable <> "No" Then
    MsgBox "You must choose an Appropriate Billing Option"
    Me.ComboBillable.BorderColor = RGB(255, 0, 0)
    Me.ComboBillable.SetFocus
    Exit Sub

Doesn't work either is it because Yes and No are text strings?

You missed that both Mile-o and I used And, not Or.
 
Thanks for all the help and the parentheses worked.

Code:
If Not (Me.ComboBillable = "Yes" Or Me.ComboBillable = "No") Then
    MsgBox "You must choose an Appropriate Billing Option"
    Me.ComboBillable.BorderColor = RGB(255, 0, 0)
    Me.ComboBillable.SetFocus
    Exit Sub
End If


Any thoughts on why this didn't work?
Code:
If Me.ComboBillable <> "Yes" Or Me.ComboBillable <> "No" Then
 

Users who are viewing this thread

Back
Top Bottom