If Then Else

  • Thread starter Thread starter a
  • Start date Start date
A

a

I don't understand why this code not work

Dim StrPr1 As String

Dim StrPr2 As String

Dim StrPr3 As String

StrPr1 = "123"

StrPr2 = "1234"

StrPr3 = "12345"

If Me.Text0.Value = StrPr1 Or StrPr2 Or StrPr3 Then

'Statment

Else

'Statment

End If
 
Thank you Fredg

fredg said:
You must repeat the criteria field each time.

If Me.Text0 = StrPr1 Or Me.Text0 = StrPr2 Or Me.Text0 = StrPr3 Then
etc....
Note: Because the Value property is a control's default property you
do not need to explicitly state it.
 
I don't understand why this code not work

Dim StrPr1 As String

Dim StrPr2 As String

Dim StrPr3 As String

StrPr1 = "123"

StrPr2 = "1234"

StrPr3 = "12345"

If Me.Text0.Value = StrPr1 Or StrPr2 Or StrPr3 Then

'Statment

Else

'Statment

End If

You must repeat the criteria field each time.

If Me.Text0 = StrPr1 Or Me.Text0 = StrPr2 Or Me.Text0 = StrPr3 Then
etc....
Note: Because the Value property is a control's default property you
do not need to explicitly state it.
 
StrPr1 = "123"

StrPr2 = "1234"

StrPr3 = "12345"

If Me.Text0.Value = StrPr1 Or StrPr2 Or StrPr3 Then

The OR operator *LOOKS* like the English language conjunction, but it isn't!
It's a Boolean algebra operator, in exactly the same way as + or - is an
arithmatic operator. As such it has a very specific meaning:

<Expr1> OR <Expr2>

evaluates <Expr1> and <Expr2> as True/False expressions. If either or both are
TRUE the OR expression is TRUE; if both are FALSE the expression is FALSE.

strPr2 and strPr3 are NOT true/false expressions - *BUT* they will be
evaluated as TRUE, since by definition 0 is FALSE and any other value is TRUE!

You're using the OR operator to compare the expression

Me.Text0.Value = StrPr1

which might be true or might be false, depending on what's in Text0, with the
expression

strPr2

which will be TRUE. The final result will be TRUE.
 
Back
Top