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

Vonik

Registered User.
Local time
Today, 04:17
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.
 

Mile-O

Back once again...
Local time
Today, 12:17
Joined
Dec 10, 2002
Messages
11,316
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:17
Joined
Aug 30, 2003
Messages
36,127
Try

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

vbaInet

AWF VIP
Local time
Today, 12:17
Joined
Jan 22, 2010
Messages
26,374
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.
 

Vonik

Registered User.
Local time
Today, 04:17
Joined
Mar 17, 2014
Messages
17
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?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:17
Joined
Aug 30, 2003
Messages
36,127
... 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? ;)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:17
Joined
Aug 30, 2003
Messages
36,127
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.
 

Vonik

Registered User.
Local time
Today, 04:17
Joined
Mar 17, 2014
Messages
17
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

Top Bottom