By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,400 Members | 981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,400 IT Pros & Developers. It's quick & easy.

If statement problem in module

P: n/a
I want my code to change the back colour to red (of a form field) if
the name is either "admin" or "meeting" or "holiday".

I tried this;

If rs!ACCOUNTNAME = "Meeting" Then
f("text" & i).BackColor = 255
ElseIf rs!ACCOUNTNAME = "Holiday" Then
f("text" & i).BackColor = 255
ElseIf rs!ACCOUNTNAME = "Admin" Then
f("text" & i).BackColor = 255

This works for all "Meeting" named fields but not the second or third
statements. I then thought I would be able to do an If / Or statement;

ElseIf rs!ACCOUNTNAME = "Holiday" Or "Meeting" or "Admin" Then
f("text" & i).BackColor = 255

But this creates an error. What am I doing wrong?

Dec 10 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 10 Dec 2006 02:34:48 -0800, "keri" <ke*********@diageo.comwrote:

It should be:
elseif x=1 or x=2 or x=3

Or alternatively:
select case x
case 1,2,3:
y.backcolor = vbRed
case else
y.backcolor = vbGreen
end select

Use the debugger to set a breakpoint at the top of your function, and
then step through, inspecting values, etc. Then programming gradually
is not such a mystery anymore.
You can also add temporary code such as:
debug.print i, y(i).backcolor
so you can easily review the color assignments.
I speculate that the "missing colors" occurs because a color is
"overwritten" in one of the next iterations.

-Tom.

>I want my code to change the back colour to red (of a form field) if
the name is either "admin" or "meeting" or "holiday".

I tried this;

If rs!ACCOUNTNAME = "Meeting" Then
f("text" & i).BackColor = 255
ElseIf rs!ACCOUNTNAME = "Holiday" Then
f("text" & i).BackColor = 255
ElseIf rs!ACCOUNTNAME = "Admin" Then
f("text" & i).BackColor = 255

This works for all "Meeting" named fields but not the second or third
statements. I then thought I would be able to do an If / Or statement;

ElseIf rs!ACCOUNTNAME = "Holiday" Or "Meeting" or "Admin" Then
f("text" & i).BackColor = 255

But this creates an error. What am I doing wrong?
Dec 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.