How is 869343 less than 869330?????

W

Walter

This is the code that for some reason isn't following standard mathematical
logic. In my current record, Me.Odometer = 869343. The last Odometer
entered was 869330. My Invalid Odometer message pops up. I put a code break
to see what's happening. varPrevOdometer is showing 869330 and Me.Odometer
is showing 869343. However, it's still going thru the steps as if 869343 is
less than 869330. The values in the "if is less than" step are correct. Can
you please explain to me when the greater than, less than rules changed??
Why is it cancelling and calling the error message?

Private Sub Odometer_BeforeUpdate(Cancel As Integer)

Dim varPrevOdometer As Variant

varPrevOdometer = Me.Parent!PrevOdometer

If Me.Odometer < varPrevOdometer Then
Cancel = True
Me.Odometer.SelStart = 0
Me.Odometer.SelLength = Len(Me.Odometer.Value)
MsgBox _
"The last odometer entered for this truck was " & _
varPrevOdometer & vbCrLf & _
"Please enter an odometer greater than or equal " & _
"to this.", , _
"Invalid Odometer Entry"

Else
Cancel = False
End If

End Sub
 
W

Walter

Thanks! That took care of it.
--
Thanks for your help!
Walter


tkelley via AccessMonster.com said:
Agreed. Except I'd use:

Dim varPrevOdometer As Long

In over ten years, I've seen very few actual reasons to use a variant.

try this:

Dim varPrevOdometer As Integer
This is the code that for some reason isn't following standard mathematical
logic. In my current record, Me.Odometer = 869343. The last Odometer
[quoted text clipped - 27 lines]
 
T

Tony Toews [MVP]

Tony said:
Dim varPrevOdometer As Integer

Just to follow up on this an Integer field is too small to use for an
odometer reading.

From A97 help "Integer stores numbers from –32,768 to 32,767 (no
fractions)"

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
T

Tony Toews [MVP]

Linq Adams via AccessMonster.com said:
Does A97 Help really say that? In every other version its -32,768 to 32,767!

You mean the question mark instead of the minus sign? That's
something weird going on with the copy and paste from A97 help and
your news reader. In your news reader headers I see
Content-Type: text/plain; charset="utf-8"
but mine shows
Content-Type: text/plain; charset=ISO-8859-1 .
What that means I haven't a clue.

Trust me, I would *not* retype that. <smile>

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
D

Douglas J. Steele

For what it's worth, I saw Tony's post as saying -32,768 to 32,767

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)
 

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

Similar Threads

sub or function not defined 4
Validation incorrect 5
entry validation 2
DMax/DLookup help 3
Validation code 4
<= 0 11
MsgBox problem 22
Cancel update from invalid data 2

Top