How to get the max value from query in ms access with visual basic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neph
    New Member
    • Dec 2010
    • 3

    How to get the max value from query in ms access with visual basic

    i need help in sql query for getting max value in ms access with visual basic 6.

    i have a table named book_info where it has a a column name "Accession Number" that has 5 inputs in it "1,2,3,4 and 5", i've tried to get the max value on it:
    Code:
    dim a as long
    a = adoAdd.RecordSource = "Select MAX(Accession Number) from book_info"
    lblAccNo= a
    with visual basic 6 and i tried to output the result in a label but it always says "false" on the value. i need to get it to be "5"
    is my syntax wrong? if it is can you reply with the correct code? Thank you
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    You can't have spaces in field names.
    Code:
    Select MAX(Accession Number) from book_info
    Alright you can, but thay need to be wrapped in square brackets in Access
    Code:
    Select MAX([Accession Number]) from book_info

    Comment

    • neph
      New Member
      • Dec 2010
      • 3

      #3
      problem solved thanks

      Comment

      Working...