Comparison code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
Back
Top