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!

Get value from autonumber field once a record has been copied.

Status
Not open for further replies.

weightinwildcat

Programmer
May 11, 2010
84
US
HI. I have been able to create a record with duplicate entries using an INSERT command that incorporates a SELECT command. Once my new record has been created, I need to get the number of an Autonumber filed for the new record so I can make entries in a couple of secondary tables. Any suggestions?
 
After the INSERT, wouldn't the new record have the highest Autonumber?
So I would just do:
[tt]
Select Max(AutonumberField) As MyLastAutoNo
From YourTable[/tt]

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
How about

Code:
Dim MyAutoNumber as long
MyAutoNumber  = currentDb.openrecordset(Select @@identity As MyAutoNumber)!MyAutoNumber
 
If you use Access 2010 (+) you may want to investigate Access Macros 2010: How To Use Data Table Macro Triggers. I would hope you just need a simple Macro (trigger) to do what you want: insert some records to other table(s) when one record is inserted to one table.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top