Results 1 to 8 of 8
  1. #1
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291

    Getting wrong answer when comparing numbers

    I have a query that compares 2 numbers. The query works for almost all situations such as:


    5.8'>5.7'
    8'>7.5'
    13.7'>11.9'

    but it has some situations that when it evaluates the numbers it gets the following answers:
    8.9'>10.8'
    9.7'>10.6'
    5.9'>18'

    Why are these comparisons not working correctly?
    What can I do to get the correct answers?

    Thanks for help

  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,521
    Based on your examples, it appears the values are being treated as text. Check the data type of the field(s), or whether some function is being applied that causes the values to be seen as text (both the Nz and Format functions can do this for example).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    It is stored as a text, can you store a number and still have a foot sign? What does it compare when it considers it a text?

  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,521
    It does an alphabetic comparison, so given your example of

    8.9'>10.8'

    8 is greater than 1. Just as with an alphabetic sort, the comparison is character by character. I would store a number but add the foot sign for display to the user. That could be as simple as putting a label right next to the textbox displaying the number. If you want to store the values as text, you'll need to convert them to numeric values to do the comparison. Options include the various "C" functions (CDec, CDbl, CCur...) or a custom function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    Any idea on how to convert 8.9' to a number in a query?

    I just tried
    LD: CDbl([Left Side DI Depth])
    and it gave me #error, I am guessing it doesnt like the foot sign.

  6. #6
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    I just tried
    LD: Val([Left Side DI Depth])
    and that seemed to give me back a number, let me test and see if this fixes everything and then I will post solved.

  7. #7
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    Everything looks to be working well, thanks once again. Just for future info the Val() worked turning a text with foot sign into a number.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I forgot about Val(); glad you didn't!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Help On Comparing Quantity in Tables
    By rochy81 in forum Access
    Replies: 2
    Last Post: 05-29-2009, 10:20 AM
  2. Substitute Teacher in need of answer key!
    By misssunshine1973 in forum Access
    Replies: 4
    Last Post: 05-14-2009, 02:25 AM
  3. Comparing between fields
    By Dashin in forum Queries
    Replies: 0
    Last Post: 02-13-2009, 08:38 AM
  4. Replies: 0
    Last Post: 12-01-2008, 03:01 PM
  5. Replies: 2
    Last Post: 11-17-2006, 01:07 PM

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