Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL stmt to get most recent data from a table

Status
Not open for further replies.

merlynsdad

Programmer
Nov 18, 2010
175
US
I'm using VBA and SQL to input data from a form into a table using autonumber as the primary. I then need to retrieve the autonumber of the row just entered into another form. I'm getting a number, but it's the number of the beginning row in the table, not the one just entered. What's the SQL statement to retrieve the most recent row? And should I put the code in the form load event, or is there a better place?

If the square peg won't fit in the round hole, sand off the corners.
 
Autonumber is a term in ACCESS, are you really using SQL Server?

In SQL Server such fields autmatically numbering are INTEGER IDENTITY, and there are several ways to get the latest value of any IDENTITY field, of a certain table or a certain connection.

See
And in Access Autonumber fields you have @@Identity, too.

See
Bye, Olaf.
 
Wrap your statements in a transaction. Create a stored procedure that does the insert and returns the primary key as an output parameter.

-------++NO CARRIER++-------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top