Conditional Expression Help Needed!

D

Dave Elliott

I need this to be 0 if the value is 0
In other words if BidDiscAmt is the same as Text385 then a value of 0
Right now the formula is correct except if there is no difference between
the two.

Forms!TimeCards![BidDiscAmt]<Forms!TimeCards![Text385]
 
G

Gijs Beukenoot

Dave Elliott bracht volgend idée uit :
I need this to be 0 if the value is 0
In other words if BidDiscAmt is the same as Text385 then a value of 0
Right now the formula is correct except if there is no difference between the
two.

Forms!TimeCards![BidDiscAmt]<Forms!TimeCards![Text385]

Convert them to a numeric value first.

Cint(Nz(Forms!TimeCards![BidDiscAmt],0))<cint(Nz(Forms!TimeCards![Text385],0))

Or use CDbl (depending on the max value and/or decimals)

Oh, and the Nz() is for checking if the value is zero...
 
D

Dave Elliott

OK, here is my code, if text392 equals text390 I do not want Lbl400 to be
visible. This would result in a zero value, they would be the same.
First line of code works ok.

Me.Lbl400.Visible = (Me.Text392) < (Me.Text390) 'UnderBilled
If CInt(Nz(Forms!TimeCards![Text392], 0)) =
CInt(Nz(Forms!TimeCards![Text390], 0)) Then 'Label Not Show Up if 0
Lbl400.Visible = False
End If



Gijs Beukenoot said:
Dave Elliott bracht volgend idée uit :
I need this to be 0 if the value is 0
In other words if BidDiscAmt is the same as Text385 then a value of 0
Right now the formula is correct except if there is no difference between
the two.

Forms!TimeCards![BidDiscAmt]<Forms!TimeCards![Text385]

Convert them to a numeric value first.

Cint(Nz(Forms!TimeCards![BidDiscAmt],0))<cint(Nz(Forms!TimeCards![Text385],0))

Or use CDbl (depending on the max value and/or decimals)

Oh, and the Nz() is for checking if the value is zero...
 
T

tina

try

Me.Lbl400.Visible = Not (Me.Text392 >= Me.Text390)

if text392 is less than text390, than Visible = True. if text392 is equal to
or greater than text 390, then Visible = False.

hth


Dave Elliott said:
OK, here is my code, if text392 equals text390 I do not want Lbl400 to be
visible. This would result in a zero value, they would be the same.
First line of code works ok.

Me.Lbl400.Visible = (Me.Text392) < (Me.Text390) 'UnderBilled
If CInt(Nz(Forms!TimeCards![Text392], 0)) =
CInt(Nz(Forms!TimeCards![Text390], 0)) Then 'Label Not Show Up if 0
Lbl400.Visible = False
End If



Gijs Beukenoot said:
Dave Elliott bracht volgend idée uit :
I need this to be 0 if the value is 0
In other words if BidDiscAmt is the same as Text385 then a value of 0
Right now the formula is correct except if there is no difference between
the two.

Forms!TimeCards![BidDiscAmt]<Forms!TimeCards![Text385]

Convert them to a numeric value first.
Cint(Nz(Forms!TimeCards![BidDiscAmt],0))<cint(Nz(Forms!TimeCards![Text385],0
))
Or use CDbl (depending on the max value and/or decimals)

Oh, and the Nz() is for checking if the value is zero...
 
G

Gijs Beukenoot

Dave Elliott schreef :
OK, here is my code, if text392 equals text390 I do not want Lbl400 to be
visible. This would result in a zero value, they would be the same.
First line of code works ok.

Me.Lbl400.Visible = (Me.Text392) < (Me.Text390) 'UnderBilled
If CInt(Nz(Forms!TimeCards![Text392], 0)) =
CInt(Nz(Forms!TimeCards![Text390], 0)) Then 'Label Not Show Up if 0
Lbl400.Visible = False
End If

The one thing is that you might want to add a :
Else
lbl400.visible = true
before the End If

But I'm still a bit puzzled here, the first line you test if it is
smaller (the <) the second line (the If) you thest if they are equal...
 
T

tina

actually, looking at it again, your first expression

Me.Lbl400.Visible = Me.Text392 < Me.Text390

should have worked just as well as the one i suggested. "Me.Text392 <
Me.Text390" is either a True statement, or a False statement. if the two
values are equal, then the statement is False. your use of the Nz function
in the If statement suggests you're getting unwanted results when one or
both values are Null. you could change your code slightly, to

Me.Lbl400.Visible = Nz(Me.Text392, 0) < Nz(Me.Text390, 0)

if you're still not getting the results you need, post the actual values
that are giving you unwanted an unwanted result, and what that result is.

hth


tina said:
try

Me.Lbl400.Visible = Not (Me.Text392 >= Me.Text390)

if text392 is less than text390, than Visible = True. if text392 is equal to
or greater than text 390, then Visible = False.

hth


Dave Elliott said:
OK, here is my code, if text392 equals text390 I do not want Lbl400 to be
visible. This would result in a zero value, they would be the same.
First line of code works ok.

Me.Lbl400.Visible = (Me.Text392) < (Me.Text390) 'UnderBilled
If CInt(Nz(Forms!TimeCards![Text392], 0)) =
CInt(Nz(Forms!TimeCards![Text390], 0)) Then 'Label Not Show Up if 0
Lbl400.Visible = False
End If



Gijs Beukenoot said:
Dave Elliott bracht volgend idée uit :
I need this to be 0 if the value is 0
In other words if BidDiscAmt is the same as Text385 then a value of 0
Right now the formula is correct except if there is no difference between
the two.

Forms!TimeCards![BidDiscAmt]<Forms!TimeCards![Text385]

Convert them to a numeric value first.
Cint(Nz(Forms!TimeCards![BidDiscAmt],0))<cint(Nz(Forms!TimeCards![Text385],0
 
D

Dave Elliott

Here is my code fired on the current event procedure of my form.
Sometimes it correctly shows and sometimes not.
Sometimes both Lbl400 and Lbl401 are visible.
It still shows Lbl400 when both Text392 and Text390 are equal.
Both Labels, Lbl400 and Lbl401 are set to be Invisible by default.

If CInt(Nz(Forms!TimeCards![Text392], 0)) =
CInt(Nz(Forms!TimeCards![Text390], 0)) Then 'Lbl400 Should Not Show Up if 0
or equal
Me.Lbl400.Visible = Not (Me.Text392 >= Me.Text390)
Lbl400.Visible = False
Else
Lbl400.Visible = True

End If
Me.Lbl400.Visible = (Me.Text392) < (Me.Text390) 'UnderBilled ' If Text392
is less than Text390 Lbl400 is visible
Me.Lbl401.Visible = (Me.Text390) > (Me.Text392) 'OverBilled ' If Text390
is greater than Text392 Lbl401 is visible
 
T

tina

okay, first, i don't understand why you're converting the data types of
these two values to Integer. is it necessary?

second, when the If expression = True, then Label400 is always going to be
hidden because that's the last line of code that will execute in the If
statement. what your code says right now is:

If Text392 = Text390 Then
Me.Lbl400.Visible = False
Me.Lbl400.Visible = False
Else
Me.Lbl400.Visible = True
End If

my understanding of what you're trying to accomplish is:

If Me.Text392 is less than Me.Text390 Then
Me.Lbl400.Visible = True
Else
'in all other situations
Me.Lbl400.Visible = False
End If

if that's correct, then the code i gave you before should work:

Me.Lbl400.Visible = Nz(Me.Text392, 0) < Nz(Me.Text390, 0)

all by itself, without an If statement.

if that's not what you're trying to accomplish, then forget the code for a
minute and post an explanation in plain sentences, so hopefully i can get on
the same page with you, and then we'll go from there.

hth
 
D

Dave Elliott

Ok, lets try this. on my sub-form in the form footer there are two text
boxes, one named over and one named under with there visible property set to
true.
They are both conditional expressions. The text boxes they refer to are on
the main form.
sub-form name is FTimeBillingSub and main form name is TimeCards.
Nz(Me.Text392,0)<Nz(Me.Text390,0) this code should make the textbox Under
on the sub-form visible.
Nz(Me.Text392,0)>Nz(Me.Text390,0) this code "
Over "
Do I need to refer to the main form via code also, like Forms!TimeCards!,
etc...???
Thanks,
 
T

tina

if the "comparison controls" are on the main form, and the textbox to be
visible or not visible is on the subform, AND the code that controls the
visible property runs from the SUBFORM, then yes, you do have to reference
the main form in the expressions, as

Nz(Me.Parent!Text392,0)<Nz(Me.Parent!Text390,0)

btw, an alternate solution using only a single label to show 'Over' or
'Under' is to:
1. create the label, then *in the Properties box* delete the text in the
Caption property.
2. use the following expression, as

Dim varTwo As Variable, varZero As Variable, strShow As String
varTwo = Nz(Me.Parent!Text392, 0)
varZero = Nz(Me.Parent!Text390, 0)

If varTwo < varZero Then
strShow = "Under"
ElseIf varTwo > varZero Then
strShow = "Over"
Else
strShow = ""
End If

Me!Lblx.Caption = strShow

hth
 

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