retrieving last used key field in a table

llaman

New Member
Joined
Jul 14, 2004
Messages
37
I have an invoice table with each invoice having a unique id_number

I need to pull the last used id_number, and increment it by one to put in with the new invoices I update the table with (using SQL statement).

This needs to be done inside of my module I wrote. Anyone know what the code for this would look like? or where i could find an example of this?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I assume you are writing the SQL INSERT statement "from scratch", using strictly code. While the AutoNumber option still is probably your best bet, you could use some code like this if you must do it through VBA:

NewKey = DMax("KeyField", "MyTable") + 1

Then you can use NewKey in your insert query.

HTH,
Mike.
 
Upvote 0
the first option is probably best, but at the point i'm at, i'd rather not go back and change it (would end up bein more work than the 2nd part, which i already have everything set up for)

can u set that equal to an Integer right off or should it be as a variant?
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,250
Members
451,757
Latest member
iours

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top