"Last" is very relative.
In the case of a sql query result, it will be the last record of the ordered set based on the ordering rules.
It appears you are trying to create a new record based on the last ID you encounter. As you are finding the technique you are using is not ideal.
There are usually two techniques used for this:
1) Use a query to find the last ID number, then increment it: SELECT MAX(fieldname) FROM tablename
This is NOT recommended because it is not safe. If you have simultaneous activity on the same operation you can easily get two instance of the same code stepping on each other using the same ID.
2) Use the features of the database to generate the ID. Usually this is accomplished with a field that is configured for identity. In Access this is called "Auto Number". When you create a record, you omit the field name from the insert statement as the database generates the value for you. This is far safer. Then the trick is getting the value out. But that's another thread.
-Peter
peterlanoie.blog