Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to combine multiple If - Else statements

Status
Not open for further replies.

RJL1

Technical User
Oct 3, 2002
228
US
I have a report that prints the contents of an order. This is the 2 pieces of code I have. I have tested them individually and they work but I do not know if it is possible to combine them.

>>First

If Me.pick_qty < qty_ord Then
Me.Box.BackColor = 16777215
Else
Me.Box.BackColor = 255
End If

>>Second

If Me.pick_status = &quot;P&quot; Then
Me.Box.BackColor = 16777215
Else
Me.Box.BackColor = 52479
End If

Any help I can get merging this 2 into one.

Thanks
Ricardo
 
First, what are the rules. In English, when do you want backcolor to be 255, 52479 or 1677215. Then you can figure out to write the if statement. Looks like if qty ordered is greater than pick quantity or pick status = &quot;P&quot; then you want 1677215, but how about the othe colors. What if pickstatus = &quot;P&quot; and order quantity < pick qty?
 
I think I had them backwards. If pick_qty < qty_ord then make the box 255 (red) if the qantities are the same make the box 16777215 (white so it will not show in the report)

pick_qty will never be greater than qty_ord

Also if the pick_status is equal to &quot;P&quot; (picked) make the box 16777215 (white so it will not show in the report) if is anything else but &quot;P&quot; make the box 52479 (yellow)

There could be a situation where the pick_status = &quot;P&quot; (they did not pick this item) in which case the pick_qty would be less than the qty_ord.

Is there anyway to handle this?

Thanks
Ricardo

 
You can do nested if's, but i'm still not sure if I understand your business rules. I'm confused because you note that if the pick_status is &quot;P&quot; it was picked but then you say there could be a situation where the pick_status is P (they did not pick).

Try the business rules first without any of the variable names. Do you want to highlight a slot in yellow if nothing was taken out of it? Then if you emptied the whole slot but it wasn't enough to fill the order highlight in red OR is it if you filled the order but there are still items left in the slot highlight in red?


You can do:

if pick_status <> &quot;P&quot; then ' You didn't pick the slot
Yellow
else 'the slot was picked
if pick_qty < qty_ord then 'items left in slot
red
else
white
end if

But, does this above take care of all your situations?
 
Sorry, I left off an end if. SHould be:

if pick_status <> &quot;P&quot; then ' You didn't pick the slot
Yellow
else 'the slot was picked
if pick_qty < qty_ord then 'items left in slot
red
else
white
end if
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top