if ... then ... also .... also ..... also

G

Guest

I am sure the answer is easy but I don't know it :-( Anyway, how do I write
in VB

the following code:

if whatever and whatever = whatever then

me!whatever = whatever

then, even if the first condition is true I want to check the next control
and do the same thing and so on. In plain English.

if the box 1 is null then
box1a = color red

also

if box 2 is null then
box2a = color red

also

if box3 is null then
bo3a = color red

and so on

So what is the command for "ALSO"?


The real code is a follow:

Private Sub Form_Current()

Dim lngBlack As Long
Dim lngRed As Long, lngYellow As Long, lngWhite As Long

lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)

If Not IsNull(Me!tVector.Value) And IsNull(Me!tVectorOK.Value) Then
Me!tVectorOK.BackColor = lngYellow



ElseIf Not IsNull(Me!tNeshap.Value) And IsNull(Me!tNeshapOK.Value) Then
Me!tNeshapOK.BackColor = lngYellow


ElseIf Not IsNull(Me!tPool.Value) And IsNull(Me!tPoolOK.Value) Then
Me!tPoolOK.BackColor = lngYellow


ElseIf Not IsNull(Me!tSeptic.Value) And IsNull(Me!tSepticOK.Value) Then
Me!tSepticOK.BackColor = lngYellow


ElseIf Not IsNull(Me!tMoveoff.Value) And IsNull(Me!tMoveoffOK.Value) Then
Me!tMoveoffOK.BackColor = lngYellow

Else
Exit Sub

End If

End Sub
 
G

Guest

I got it :) all I had to do is to

place a End If at the end of each statement and convert all the Elseif in IF
 
G

Guest

Silvio,

Perhaps your code as you wrote it gives the values you intend, but I’d
recommend using parentheses to make your intention explicit to yourself and
whoever inherits your code.

For example, on your first test, let’s call your conditions by the following
shorthand:

A IsNull(tVector)
B IsNull(tVectorOK)

Do you intend (Not A) And B or Not (A And B)?

The truth table expands as follows:

A B Not A A And B (Not A) And B Not(A And B)
T T F T F F
T F F F F T
F T T F T T
F F T F F T

Obviously, the last two columns are not equivalent.

Hope that helps.
Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top