If Values are the same, do nothing?

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
D

Dave Elliott

How can I make the below do nothing if the values are the same?

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
 
Dave Elliott said:
How can I make the below do nothing if the values are the same?

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then

Either of two ways. 1:

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
' do nothing
Else
' do something
End If

Or 2:


If Me.[Bidtxt].Value <> CCur(Me.[Text331].Value) Then
' do someting here, because the values are not equal
End If
 
If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
' Do nothing here
Else
' Your code to do something
End If


But then it is shorter to use:

If Me.[Bidtxt].Value <> CCur(Me.[Text331].Value) Then
' Your code to do something
End If

or even:

If Not (Me.[Bidtxt].Value = CCur(Me.[Text331].Value)) Then
' Your code to do something
End If
 
Tried this but it still show OVER if the values are equal???

If Me.[Bidtxt].Value < CCur(Me.[Text331].Value) Then
MsgBox "Amount is Under Suggested Price"
End If

If Me.[Bidtxt].Value > CCur(Me.[Text331].Value) Then
MsgBox "Amount is Over Suggested Price"

ElseIf Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
'Do Nothing
End If




Dirk Goldgar said:
Dave Elliott said:
How can I make the below do nothing if the values are the same?

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then

Either of two ways. 1:

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
' do nothing
Else
' do something
End If

Or 2:


If Me.[Bidtxt].Value <> CCur(Me.[Text331].Value) Then
' do someting here, because the values are not equal
End If

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
I know that this sounds stupid, but are you sure that the values are
precisely equal? If they are numeric and one is entered directly but
the other is calculated, and/or they are calculated differently, the
wonders of rounding and digital representation may mean that two
numbers that "should" be equal actually differ by the amount of a
round-off error. Similarly if they are numeric but of different
precisions.

Tried this but it still show OVER if the values are equal???

If Me.[Bidtxt].Value < CCur(Me.[Text331].Value) Then
MsgBox "Amount is Under Suggested Price"
End If

If Me.[Bidtxt].Value > CCur(Me.[Text331].Value) Then
MsgBox "Amount is Over Suggested Price"

ElseIf Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
'Do Nothing
End If




Dirk Goldgar said:
Dave Elliott said:
How can I make the below do nothing if the values are the same?

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then

Either of two ways. 1:

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
' do nothing
Else
' do something
End If

Or 2:


If Me.[Bidtxt].Value <> CCur(Me.[Text331].Value) Then
' do someting here, because the values are not equal
End If

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 
One is displayed as $55.00 [Bidtxt] and [Text331] displayed as 55 because
it gets its value form anothert control.
The first control is bound and the last simply equals another field from
another table.


Peter R. Fletcher said:
I know that this sounds stupid, but are you sure that the values are
precisely equal? If they are numeric and one is entered directly but
the other is calculated, and/or they are calculated differently, the
wonders of rounding and digital representation may mean that two
numbers that "should" be equal actually differ by the amount of a
round-off error. Similarly if they are numeric but of different
precisions.

Tried this but it still show OVER if the values are equal???

If Me.[Bidtxt].Value < CCur(Me.[Text331].Value) Then
MsgBox "Amount is Under Suggested Price"
End If

If Me.[Bidtxt].Value > CCur(Me.[Text331].Value) Then
MsgBox "Amount is Over Suggested Price"

ElseIf Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
'Do Nothing
End If




Dirk Goldgar said:
How can I make the below do nothing if the values are the same?

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then

Either of two ways. 1:

If Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
' do nothing
Else
' do something
End If

Or 2:


If Me.[Bidtxt].Value <> CCur(Me.[Text331].Value) Then
' do someting here, because the values are not equal
End If

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher
 
Dave Elliott said:
Tried this but it still show OVER if the values are equal???

If Me.[Bidtxt].Value < CCur(Me.[Text331].Value) Then
MsgBox "Amount is Under Suggested Price"
End If

If Me.[Bidtxt].Value > CCur(Me.[Text331].Value) Then
MsgBox "Amount is Over Suggested Price"

ElseIf Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
'Do Nothing
End If

That could be better written as

'----- start of revised code #1 -----
If Me!Bidtxt < CCur(Me!Text331) Then
MsgBox "Amount is Under Suggested Price"
ElseIf Me!Bidtxt > CCur(Me!Text331) Then
MsgBox "Amount is Over Suggested Price"
Else
'Equal - do nothing
End If

'----- end of revised code #1 -----

Or even as

'----- start of revised code #2 -----
Select Case Me!Bidtxt
Case Is < CCur(Me!Text331)
MsgBox "Amount is Under Suggested Price"
Case Is > CCur(Me!Text331)
MsgBox "Amount is Over Suggested Price"
Case Else
'Equal - do nothing
End Select

'----- end of revised code #2 -----

However, if the code you posted is telling you that Bidtxt is over
Text331 event though you believe the values are equal, then I agree with
Peter Fletcher -- the values probably aren't really precisely equal, but
their differences are hidden from you by formatting; or else the value
of Text331 hasn't yet been calculated at the time when this code is
executed. You mention that Text331 "gets its value form another
control". What is the controlsource of Text331, where does that "other
control" get its value, and when is this code being executed?

Also, what is the Data Type (not the Format) of the field to which
Bidtxt is bound? It seems the Format is Currency; is the Data Type
also Currency?
 
Text331 gets its code from 2 controls on the form Text331 equals
=Nz([Amount]+[Text330],0)
Text331 is displayed as 55, while Bidtxt is displayed as $55.00
The other control is bound is (Bidtxt) and in currency format.


Dirk Goldgar said:
Dave Elliott said:
Tried this but it still show OVER if the values are equal???

If Me.[Bidtxt].Value < CCur(Me.[Text331].Value) Then
MsgBox "Amount is Under Suggested Price"
End If

If Me.[Bidtxt].Value > CCur(Me.[Text331].Value) Then
MsgBox "Amount is Over Suggested Price"

ElseIf Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
'Do Nothing
End If

That could be better written as

'----- start of revised code #1 -----
If Me!Bidtxt < CCur(Me!Text331) Then
MsgBox "Amount is Under Suggested Price"
ElseIf Me!Bidtxt > CCur(Me!Text331) Then
MsgBox "Amount is Over Suggested Price"
Else
'Equal - do nothing
End If

'----- end of revised code #1 -----

Or even as

'----- start of revised code #2 -----
Select Case Me!Bidtxt
Case Is < CCur(Me!Text331)
MsgBox "Amount is Under Suggested Price"
Case Is > CCur(Me!Text331)
MsgBox "Amount is Over Suggested Price"
Case Else
'Equal - do nothing
End Select

'----- end of revised code #2 -----

However, if the code you posted is telling you that Bidtxt is over
Text331 event though you believe the values are equal, then I agree with
Peter Fletcher -- the values probably aren't really precisely equal, but
their differences are hidden from you by formatting; or else the value
of Text331 hasn't yet been calculated at the time when this code is
executed. You mention that Text331 "gets its value form another
control". What is the controlsource of Text331, where does that "other
control" get its value, and when is this code being executed?

Also, what is the Data Type (not the Format) of the field to which
Bidtxt is bound? It seems the Format is Currency; is the Data Type
also Currency?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Forgot , Data Type for both is Currency as well as format in currency


Dirk Goldgar said:
Dave Elliott said:
Tried this but it still show OVER if the values are equal???

If Me.[Bidtxt].Value < CCur(Me.[Text331].Value) Then
MsgBox "Amount is Under Suggested Price"
End If

If Me.[Bidtxt].Value > CCur(Me.[Text331].Value) Then
MsgBox "Amount is Over Suggested Price"

ElseIf Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
'Do Nothing
End If

That could be better written as

'----- start of revised code #1 -----
If Me!Bidtxt < CCur(Me!Text331) Then
MsgBox "Amount is Under Suggested Price"
ElseIf Me!Bidtxt > CCur(Me!Text331) Then
MsgBox "Amount is Over Suggested Price"
Else
'Equal - do nothing
End If

'----- end of revised code #1 -----

Or even as

'----- start of revised code #2 -----
Select Case Me!Bidtxt
Case Is < CCur(Me!Text331)
MsgBox "Amount is Under Suggested Price"
Case Is > CCur(Me!Text331)
MsgBox "Amount is Over Suggested Price"
Case Else
'Equal - do nothing
End Select

'----- end of revised code #2 -----

However, if the code you posted is telling you that Bidtxt is over
Text331 event though you believe the values are equal, then I agree with
Peter Fletcher -- the values probably aren't really precisely equal, but
their differences are hidden from you by formatting; or else the value
of Text331 hasn't yet been calculated at the time when this code is
executed. You mention that Text331 "gets its value form another
control". What is the controlsource of Text331, where does that "other
control" get its value, and when is this code being executed?

Also, what is the Data Type (not the Format) of the field to which
Bidtxt is bound? It seems the Format is Currency; is the Data Type
also Currency?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Dave Elliott said:
Text331 gets its code from 2 controls on the form Text331 equals
=Nz([Amount]+[Text330],0)
Text331 is displayed as 55, while Bidtxt is displayed as $55.00
The other control is bound is (Bidtxt) and in currency format.


Dirk Goldgar said:
Dave Elliott said:
Tried this but it still show OVER if the values are equal???

If Me.[Bidtxt].Value < CCur(Me.[Text331].Value) Then
MsgBox "Amount is Under Suggested Price"
End If

If Me.[Bidtxt].Value > CCur(Me.[Text331].Value) Then
MsgBox "Amount is Over Suggested Price"

ElseIf Me.[Bidtxt].Value = CCur(Me.[Text331].Value) Then
'Do Nothing
End If

That could be better written as

'----- start of revised code #1 -----
If Me!Bidtxt < CCur(Me!Text331) Then
MsgBox "Amount is Under Suggested Price"
ElseIf Me!Bidtxt > CCur(Me!Text331) Then
MsgBox "Amount is Over Suggested Price"
Else
'Equal - do nothing
End If

'----- end of revised code #1 -----

Or even as

'----- start of revised code #2 -----
Select Case Me!Bidtxt
Case Is < CCur(Me!Text331)
MsgBox "Amount is Under Suggested Price"
Case Is > CCur(Me!Text331)
MsgBox "Amount is Over Suggested Price"
Case Else
'Equal - do nothing
End Select

'----- end of revised code #2 -----

However, if the code you posted is telling you that Bidtxt is over
Text331 event though you believe the values are equal, then I agree
with Peter Fletcher -- the values probably aren't really precisely
equal, but their differences are hidden from you by formatting; or
else the value of Text331 hasn't yet been calculated at the time
when this code is executed. You mention that Text331 "gets its
value form another control". What is the controlsource of Text331,
where does that "other control" get its value, and when is this code
being executed?

Also, what is the Data Type (not the Format) of the field to which
Bidtxt is bound? It seems the Format is Currency; is the Data Type
also Currency?

It seems as though the values should be equal, but it could be that the
value of Text331 hasn't been calculated yet when your code runs. Where
is that code in the form's module -- what event?
 
Back
Top