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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to capture and reuse primary key, getting type mismatch.

Status
Not open for further replies.

bcapps

Technical User
Jul 11, 2001
23
US
I have code in an ASP page to insert some data, I want to insert into one table, retrieve the primary key from that entry and then insert that into another table. Here is what I have so far and I am getting type mismatch when trying to insert into the second table:

conn.Execute "insert into tblOne (AName) values ('" & Request.Form("BName") & "')"

set ANum = Conn.Execute("SELECT MAX(recordID) FROM tblOne")

conn.Execute "insert into tblTwo (tblOneNum) values (" & ANum & ")"

I know I must be doing something wrong, but don't know what.

Thanks
 
Try...

Code:
conn.Execute "insert into tblTwo (tblOneNum) values (" & ANum("recordID")& ")"

ANum is an Recordset witch contains a field named recordID and u dont use it correctly.
Hope this works. ________
George, M
 
I tried that and now I am getting:

Item cannot be found in the collection corresponding to the requested name or ordinal.

Thanks
 
There is one little change...

Code:
set ANum = Conn.Execute("SELECT MAX(recordID) as max FROM tblOne")
conn.Execute "insert into tblTwo (tblOneNum) values (" & ANum("max")& ")"

This should work... ________
George, M
 
It's Working!!! :) :) :)

I Can't thank you enough!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top