|
|
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 -- Thanks for your help! Walter
|
|
try this:
Dim varPrevOdometer As Integer
"Walter" wrote:
[Quoted Text] > 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 > -- > Thanks for your help! > Walter
|
|
Agreed. Except I'd use:
Dim varPrevOdometer As Long
In over ten years, I've seen very few actual reasons to use a variant.
Tony wrote:
[Quoted Text] >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] >> >> End Sub
-- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1
|
|
Thanks! That took care of it. -- Thanks for your help! Walter
"tkelley via AccessMonster.com" wrote:
[Quoted Text] > Agreed. Except I'd use: > > Dim varPrevOdometer As Long > > In over ten years, I've seen very few actual reasons to use a variant. > > > Tony wrote: > >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] > >> > >> End Sub > > -- > Message posted via AccessMonster.com > http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1> >
|
|
Tony <Tony[ at ]discussions.microsoft.com> wrote:
[Quoted Text] >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/
|
|
|
[Quoted Text] >From A97 help "Integer stores numbers from –32,768 to 32,767 (no >fractions)"
Does A97 Help really say that? In every other version its -32,768 to 32,767!
-- There's ALWAYS more than one way to skin a cat!
Answers/posts based on Access 2000/2003
Message posted via http://www.accessmonster.com
|
|
"Linq Adams via AccessMonster.com" <u28780[ at ]uwe> wrote:
[Quoted Text] >>From A97 help "Integer stores numbers from ?32,768 to 32,767 (no >>fractions)" > >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/
|
|
For what it's worth, I saw Tony's post as saying -32,768 to 32,767
-- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please)
"Tony Toews [MVP]" <ttoews[ at ]telusplanet.net> wrote in message news:flp8l4l1sij7dgcosljjvusooodl7n14ea[ at ]4ax.com...
[Quoted Text] > "Linq Adams via AccessMonster.com" <u28780[ at ]uwe> wrote: > >>>From A97 help "Integer stores numbers from ?32,768 to 32,767 (no >>>fractions)" >> >>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/
|
|
|
|
"Linq Adams via AccessMonster.com" <u28780[ at ]uwe> wrote:
[Quoted Text] >You mean Access isn't the only quirky software? > >;0)>
Hehehehe
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/
|
|
|