Comparison code

S

Stasia

I am trying to make a report that shows how many units are in stock and what the level (number) has to get down to before it's time to re-order more. When that number gets below the re-order level, I want the units to reorder to become visible. I have the properties of the units to reorder set to Visible=no and my code looks like this. I am working from the Detail section, OnPrint.
If Me.Units_on_Hand <= Me. ReorderLevel then
Me.Units_to_Order.Visible=True
EndIf
EndSub
The wrong numbers become visible and I get no error. I am really baffled. Any suggestions would be greatly appreciated.
 
A

Allen Browne

Here is a code-free solution.

On your report, add a text box with this Control Source:
=IIf([Units_on_Hand] < [ReorderLevel], [Units_on_Hand], Null)

(Make sure this text box does not have the same Name as one of the fields.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Stasia said:
I am trying to make a report that shows how many units are in stock and
what the level (number) has to get down to before it's time to re-order
more. When that number gets below the re-order level, I want the units to
reorder to become visible. I have the properties of the units to reorder
set to Visible=no and my code looks like this. I am working from the Detail
section, OnPrint.
If Me.Units_on_Hand <= Me. ReorderLevel then
Me.Units_to_Order.Visible=True
EndIf
EndSub
The wrong numbers become visible and I get no error. I am really baffled.
Any suggestions would be greatly appreciated.
 
S

Stasia

Thanks for your reply Allen, I tried your approach but I got a pop up window asking for an if parameter.

Also, why do you (and others) spell "IF" as "IIF" on this discussion board?

Allen Browne said:
Here is a code-free solution.

On your report, add a text box with this Control Source:
=IIf([Units_on_Hand] < [ReorderLevel], [Units_on_Hand], Null)

(Make sure this text box does not have the same Name as one of the fields.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Stasia said:
I am trying to make a report that shows how many units are in stock and
what the level (number) has to get down to before it's time to re-order
more. When that number gets below the re-order level, I want the units to
reorder to become visible. I have the properties of the units to reorder
set to Visible=no and my code looks like this. I am working from the Detail
section, OnPrint.
If Me.Units_on_Hand <= Me. ReorderLevel then
Me.Units_to_Order.Visible=True
EndIf
EndSub
The wrong numbers become visible and I get no error. I am really baffled.
Any suggestions would be greatly appreciated.
 
D

Douglas J. Steele

IIf is different than If: it stands for Immediate If, and has 3 parts.

IIf(expr, truepart, falsepart)

expr is an expression that evaluates to either True or False.
truepart is what's done if expr is True
falsepart is what's done if expr is False

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Stasia said:
Thanks for your reply Allen, I tried your approach but I got a pop up
window asking for an if parameter.
Also, why do you (and others) spell "IF" as "IIF" on this discussion board?

Allen Browne said:
Here is a code-free solution.

On your report, add a text box with this Control Source:
=IIf([Units_on_Hand] < [ReorderLevel], [Units_on_Hand], Null)

(Make sure this text box does not have the same Name as one of the fields.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Stasia said:
I am trying to make a report that shows how many units are in stock
and
what the level (number) has to get down to before it's time to re-order
more. When that number gets below the re-order level, I want the units to
reorder to become visible. I have the properties of the units to reorder
set to Visible=no and my code looks like this. I am working from the Detail
section, OnPrint.
If Me.Units_on_Hand <= Me. ReorderLevel then
Me.Units_to_Order.Visible=True
EndIf
EndSub
The wrong numbers become visible and I get no error. I am really
baffled.
Any suggestions would be greatly appreciated.
 
J

John Spencer (MVP)

Because we are using the IIF function (Immediate IF) which is the one available
in Access SQL and in control sources. You can use "If" in VBA code, but that is
a different library. In VBA you can also use the IIF function (IF, I recall correctly).
Thanks for your reply Allen, I tried your approach but I got a pop up window asking for an if parameter.

Also, why do you (and others) spell "IF" as "IIF" on this discussion board?

Allen Browne said:
Here is a code-free solution.

On your report, add a text box with this Control Source:
=IIf([Units_on_Hand] < [ReorderLevel], [Units_on_Hand], Null)

(Make sure this text box does not have the same Name as one of the fields.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Stasia said:
I am trying to make a report that shows how many units are in stock and
what the level (number) has to get down to before it's time to re-order
more. When that number gets below the re-order level, I want the units to
reorder to become visible. I have the properties of the units to reorder
set to Visible=no and my code looks like this. I am working from the Detail
section, OnPrint.
If Me.Units_on_Hand <= Me. ReorderLevel then
Me.Units_to_Order.Visible=True
EndIf
EndSub
The wrong numbers become visible and I get no error. I am really baffled.
Any suggestions would be greatly appreciated.
 
A

Allen Browne

If Access is asking for a parameter, it means that it does not understand
the name of something. The question in the parameter box will tell you which
name it does not understand about.

As Douglas and John explained, IIf() is the Immediate If function.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Stasia said:
Thanks for your reply Allen, I tried your approach but I got a pop up
window asking for an if parameter.
Also, why do you (and others) spell "IF" as "IIF" on this discussion board?

Allen Browne said:
Here is a code-free solution.

On your report, add a text box with this Control Source:
=IIf([Units_on_Hand] < [ReorderLevel], [Units_on_Hand], Null)

(Make sure this text box does not have the same Name as one of the fields.)


Stasia said:
I am trying to make a report that shows how many units are in stock
and
what the level (number) has to get down to before it's time to re-order
more. When that number gets below the re-order level, I want the units to
reorder to become visible. I have the properties of the units to reorder
set to Visible=no and my code looks like this. I am working from the Detail
section, OnPrint.
If Me.Units_on_Hand <= Me. ReorderLevel then
Me.Units_to_Order.Visible=True
EndIf
EndSub
The wrong numbers become visible and I get no error. I am really
baffled.
 

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