Results 1 to 6 of 6
  1. #1
    falen_boyz is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    3

    Post MAX function is not working in Access 2007 DB

    Hello, I was using a software using MS Access 2007 as database. It was working fine till morning when I got problem with MAX function. I was using a serial number to record transactions but today when I tried to enter transaction the MAX function was not giving maximum value in database. Actually I had reached to 9999 serial and when I created 10000 entry it stopped working. Now every time I try it comes up with 9999 as maximum value instead of 10000. What could be problem. I am using this query to perform function.

    SQL Query= select MAX(variable) from table where variable like 'I%'.

  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,652
    One possibility is that the data type of your field is text. That would cause an alphabetic sort, which would make 9999 greater than 10000.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    falen_boyz is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    3
    Quote Originally Posted by pbaldy View Post
    One possibility is that the data type of your field is text. That would cause an alphabetic sort, which would make 9999 greater than 10000.
    Yes, you are right. It is a text field and I can't find any solution. Any solution in your mind?

  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,652
    Either change the field to numeric or use CLng() in your SQL. I'd do the first since the field is treated as a number.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    falen_boyz is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    3
    Quote Originally Posted by pbaldy View Post
    Either change the field to numeric or use CLng() in your SQL. I'd do the first since the field is treated as a number.
    I can't change field to numeric as I am saving serial numbers as SI0000. It did not cause any problems when 999 and 1000 serial numbers were inserted.

  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,652
    Well, you're seeing the inherent conflict of saving a value as text but wanting it to act like a number. I would store the numeric part separately from the text part and put them together in forms/reports. You can also try this in your SQL

    Max(CLng(Mid(FieldName, 2)))
    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. Access 2007 db forms not working in Access 2010
    By Butterfly13 in forum Access
    Replies: 2
    Last Post: 09-07-2012, 12:45 PM
  2. [access 2007] Update Query And Function
    By Zoroxeus in forum Queries
    Replies: 4
    Last Post: 04-16-2012, 04:19 PM
  3. Login ID Code for Access 2007 not working
    By amangupts in forum Programming
    Replies: 25
    Last Post: 07-07-2011, 01:28 PM
  4. Replies: 1
    Last Post: 12-02-2010, 11:08 PM
  5. .Edit function in Access 2007
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 11-24-2010, 10:19 AM

Tags for this Thread

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