use SQLPrimaryKeys function to get the primary key colunm name and use that name in max method and use the result in the select statement.....
Try it all the best