SQL statement to return highest value in autonumber field?

nharrison

Registered User.
Local time
Today, 14:45
Joined
Jun 11, 2009
Messages
55
This is more of an SQL question than a query issue.

I want to determine the max value of an autonumber field, b/c this is an easy way to access the last created record in a table. I can't use DoCmd.GoToRecord , , Last,
because I have a sort active on my recordset, and that navigates to the last person alphabetically by last name - not what I need.

I know you can use SELECT Max("Contact ID") FROM "Contacts", but how do I assign what is returned by this to a global variable I can use in VBA procedures?
 
Have you considered using the dmax() function?
 
This is more of an SQL question than a query issue.

I want to determine the max value of an autonumber field, b/c this is an easy way to access the last created record in a table. I can't use DoCmd.GoToRecord , , Last,
because I have a sort active on my recordset, and that navigates to the last person alphabetically by last name - not what I need.

I know you can use SELECT Max("Contact ID") FROM "Contacts", but how do I assign what is returned by this to a global variable I can use in VBA procedures?

This type of question comes up all the time. If you search on DMax, a common method of finding the highest previous value, you should find any number of threads. Perhaps that will provide you with a good start.

Looks like Ken beat me to the post with a slighly shorter response that says the same thing. With two votes Aye, I suggest you look into DMax().
 
Last edited:

Users who are viewing this thread

Back
Top Bottom