Results 1 to 7 of 7
  1. #1
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737

    BeforeUpdate: Why is 50 greater than 250?

    In response to post number 14 in this thread https://www.accessforums.net/showthr...905#post335905


    (where OP wants to know the number of pallets needed to contain n received items AND know the remainder on a partial pallet if there is any) I am submitting the details of a problem I encountered while proposing a solution for that thread. The intent is to try to save everybody else some hair pulling, but then again, it would not surprise me to know I am the only so-called 'expert' on the planet that did not know the cause. BTW, I think this forum tagged me as a VIP, but that's a different issue.

    I created a form with 4 unbound textboxes - txtRecdQty, txtPallets, txtStack, txtMod (Stack is the term OP used to define the number of items that would be stacked on a pallet). One of the data validations I wanted to impose in the BeforeUpdate event of txtStack was to not allow txtStack to be greater than txtRecdQty since a stack amount could not be greater than the amount received. If I put 250 in txtRecdQty and 50 in txtStack, the validation message triggered and said that the stack quantity could not be greater than the received quantity. Of course, this does not make sense. Here is that portion of the code, followed by everything I could think of to test in the immediate window with the answers on the same line to save space:

    Code:
    If Me.txtStack > Me.txtRecdQty Then
        MsgBox "Stack quantity cannot be greater than received quantity"
        Cancel = True
        bolResetStack = True
        With Me.txtStack
            .Undo
            .SelStart = 0
            .SelLength = Len(Me.txtStack)
        End With
        'Me.Refresh
        Exit Sub
    Else
        setCtlSources False
    End If
    ?me.txtRecdQty.Oldvalue 100
    ?me.txtStack.Oldvalue 20
    ?me.txtRecdQty.value 100
    ?me.txtStack.Value 20
    ?Me.txtStack.oldvalue > Me.txtRecdQty.OldValue True
    ?Me.txtStack > Me.txtRecdQty True
    ?me.txtStack.Value > me.txtRecdQty.Value True
    ?isnumeric(Me.txtStack) True

    Additional info:
    I was probably using different values when performing the following, but the immediate window tests shown were based on 100 and 20.
    - Validation was sometimes correct when form was opened the first time.
    - If not, compacting/closing/reopening db might fix it for one or more iterations.
    - If not, a complete restart of the laptop might fix the problem for one or more iterations.
    Once I stuck with 240 received and 50 for the stack, it always failed to evaluate properly, regardless of repeating those attempts to fix it.

    Hopefully I provided enough clues. Anyone want to guess why txtStack (50) is greater than txtRecdQty (250)? I hate to say how long it took me to figure it out.
    If you think of a possible cause not already posted, take a stab at it. I'll wait for a few guesses before spilling the beans.
    Last edited by Micron; 10-25-2016 at 08:20 PM. Reason: added on
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    It would appear you got an alphabetic comparison rather than a numeric one. I'd look at textbox formats as a potential cause, but would probably not dig too deep and just use a conversion function in the test...because I'm lazy.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    I agree with Paul but just thought 'because less is more'

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Hey, no peeking over shoulders during tests!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Either I gave too much info or you guys are just awsomer than me (like my new word?). I shall move to the back of the class. Kudos to you both anyway.

    Yes, alphabetically, 50 is greater than 250. I spent much of my time trying to prove that theory, which I surmised early on. I couldn't find a way to vet the data type (and in the case of numerics, the field size) of an unbound textbox since IsNumeric() is of zero help. I had to ask my kid.

    I moved the operation to a button click since there were other things I wanted to do with the controls which the BeforeUpdate only made more difficult with the issues it introduced. If the values pass other validations, they are coerced (CLng) before the greater than comparison is made.

    Thanks for commenting.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Oh, the thread title was enough for me to guess you were getting an alphabetic comparison. In a brief test, I can duplicate your result with unbound textboxes, and fix the problem simply by giving the textboxes a numeric format like "General Number". It seems to be enough to tell Access to treat the values as numbers instead of text.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Nice to know that would solve the hierarchy issue.
    Did you know that for 250/40, choosing General Number with 0 decimal places is 6.25 but as Fixed with 0 decimal places it is 6?
    I guess it's too much to ask for a little consistency.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. BeforeUpdate in a form
    By tcheck in forum Access
    Replies: 4
    Last Post: 07-28-2016, 03:09 PM
  2. Replies: 1
    Last Post: 03-19-2015, 05:22 PM
  3. Using the Form.BeforeUpdate property
    By Access_Novice in forum Programming
    Replies: 6
    Last Post: 01-01-2014, 08:45 PM
  4. Beforeupdate to early
    By R_Badger in forum Forms
    Replies: 3
    Last Post: 02-09-2012, 10:38 AM
  5. Validation BeforeUpdate Errors
    By huv123 in forum Programming
    Replies: 3
    Last Post: 02-07-2011, 10:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums