If Statement for Negative Number

D

Dave Elliott

I have a Textbox and a Label on my main form.
If the Textbox value is a negative number, i.e. (format Currency) then
Label30 needs to be visible, tried code below but with no results,
What am I doing wrong?

If ([Text377]) < 0 Then
Label30.Visible = True
End If
 
D

Dave Elliott

The result of Text377 looks like this ($55.00)
So the customer would have a credit balance of $55.00, only in Text377 it
is a negative number.
Tried below code, it didnt work.

Peter R. Fletcher said:
Where are you putting this code?

It needs to be in Form_Current (If Not Me.NewRecord) _and_ in the
Textbox's AfterUpdate Event. The Form_Current code should look like:

If Me.NewRecord Or IsNull([Text377]) Then
Label30.Visible = False
Else
Label30.Visible = ([Text377] < 0)
End If

The Text377_AfterUpdate code should look like:

If IsNull([Text377]) Then
Label30.Visible = False
Else
Label30.Visible = ([Text377] < 0)
End If

In both cases, you don't know the initial state of Label30, so you
need _explicitly_ to make it either Visible or inVisible, depending on
the value of [Text377], and it is good practice to handle the Null
case explicitly before you do numeric operations on the contents of a
field or Textbox. You don't need to do this if [Text377] is a Required
Field (and so can't be Null).

I have a Textbox and a Label on my main form.
If the Textbox value is a negative number, i.e. (format Currency) then
Label30 needs to be visible, tried code below but with no results,
What am I doing wrong?

If ([Text377]) < 0 Then
Label30.Visible = True
End If


Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher
 
D

Dave Elliott

Text377 is a computed control, it gets it's data from another control, it
simply shows what the other control is. The form I have for the control is
currency, should I take this out? Any other changes I should make?

Peter R. Fletcher said:
Is the data inText377 entered by the user or computed? If it is a
computed Control, the AfterUpdate code needs to go in the AfterUpdate
Event of any user-completed Control that contributes to it, not in the
AfterUpdate event of Text377 itself (which never fires, in that case).

One further thought, if it is a computed Control - are you using
Format () to format it, by any chance? If you are, it is a string
rather than a numeric, and will never satisfy the If condition.

The result of Text377 looks like this ($55.00)
So the customer would have a credit balance of $55.00, only in Text377 it
is a negative number.
Tried below code, it didnt work.

Peter R. Fletcher said:
Where are you putting this code?

It needs to be in Form_Current (If Not Me.NewRecord) _and_ in the
Textbox's AfterUpdate Event. The Form_Current code should look like:

If Me.NewRecord Or IsNull([Text377]) Then
Label30.Visible = False
Else
Label30.Visible = ([Text377] < 0)
End If

The Text377_AfterUpdate code should look like:

If IsNull([Text377]) Then
Label30.Visible = False
Else
Label30.Visible = ([Text377] < 0)
End If

In both cases, you don't know the initial state of Label30, so you
need _explicitly_ to make it either Visible or inVisible, depending on
the value of [Text377], and it is good practice to handle the Null
case explicitly before you do numeric operations on the contents of a
field or Textbox. You don't need to do this if [Text377] is a Required
Field (and so can't be Null).

On Sun, 07 Nov 2004 17:57:40 GMT, "Dave Elliott"

I have a Textbox and a Label on my main form.
If the Textbox value is a negative number, i.e. (format Currency) then
Label30 needs to be visible, tried code below but with no results,
What am I doing wrong?

If ([Text377]) < 0 Then
Label30.Visible = True
End If



Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher


Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher
 
D

Dave Elliott

Thanks for your help, unfortunately I am not having any luck, tried the
after update event code with no results.

Peter R. Fletcher said:
Assuming that the contents of the control is a computed _numeric_
_value_, and you are simply using the Format _Property_ of the Control
to display it the way you want it to look, numeric tests should work
properly on its contents. However, as I noted, the AfterUpdate code
needs to go in the AfterUpdate Event of the Control that accepts the
data from the user - AfterUpdate does not fire for a computed
Control..

Text377 is a computed control, it gets it's data from another control, it
simply shows what the other control is. The form I have for the control is
currency, should I take this out? Any other changes I should make?

Peter R. Fletcher said:
Is the data inText377 entered by the user or computed? If it is a
computed Control, the AfterUpdate code needs to go in the AfterUpdate
Event of any user-completed Control that contributes to it, not in the
AfterUpdate event of Text377 itself (which never fires, in that case).

One further thought, if it is a computed Control - are you using
Format () to format it, by any chance? If you are, it is a string
rather than a numeric, and will never satisfy the If condition.

On Sun, 07 Nov 2004 19:45:49 GMT, "Dave Elliott"

The result of Text377 looks like this ($55.00)
So the customer would have a credit balance of $55.00, only in Text377
it
is a negative number.
Tried below code, it didnt work.

"Peter R. Fletcher" <pfletch(at)fletchers(hyphen)uk.com> wrote in
message
Where are you putting this code?

It needs to be in Form_Current (If Not Me.NewRecord) _and_ in the
Textbox's AfterUpdate Event. The Form_Current code should look like:

If Me.NewRecord Or IsNull([Text377]) Then
Label30.Visible = False
Else
Label30.Visible = ([Text377] < 0)
End If

The Text377_AfterUpdate code should look like:

If IsNull([Text377]) Then
Label30.Visible = False
Else
Label30.Visible = ([Text377] < 0)
End If

In both cases, you don't know the initial state of Label30, so you
need _explicitly_ to make it either Visible or inVisible, depending on
the value of [Text377], and it is good practice to handle the Null
case explicitly before you do numeric operations on the contents of a
field or Textbox. You don't need to do this if [Text377] is a Required
Field (and so can't be Null).

On Sun, 07 Nov 2004 17:57:40 GMT, "Dave Elliott"

I have a Textbox and a Label on my main form.
If the Textbox value is a negative number, i.e. (format Currency)
then
Label30 needs to be visible, tried code below but with no results,
What am I doing wrong?

If ([Text377]) < 0 Then
Label30.Visible = True
End If



Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher



Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher


Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher
 

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