This topic is locked

Add Page Primary Key

9/11/2008 10:15:42 PM
ASPRunnerPro General questions
M
mccreelake author

Hello,
I am trying to execute an INSERT INTO statement as an AfterAdd() event. I need to use the primary key from the record that is added on the add page as one of the values to insert; however, I keep getting errors. I have tried DICT("EventID"), KEYS("EventID")...
How do you reference the primary key field of an added record during an AfterAdd() event?
Thanks!

J
Jane 9/12/2008

Hi,
key values are in the keys collection.

It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

M
mccreelake author 9/12/2008

Hi, I used the following code to pull the new primary key from the added record. Does it look okay? It works well.

str = "select max([EventID]) from Events"

Set rsTemp = server.CreateObject("ADODB.Recordset")
rsTemp.open str, dbConnection
strSQLInsert = "INSERT INTO Groups_Events (Events_EventID, Groups_GroupID, AttnPeriod, Groups_EventCategories_GroupEventCategoryID, NWBPUB, NWBUSR, NWBADM) "

strSQLInsert = strSQLInsert & "values (" & rsTemp(0) & "," & dict("Orig_GroupID") & ",'" & dict("Orig_AttnPeriod") & "'," & dict("Orig_GroupEventCategoryID") & "," & dict("NWBPUB") & "," & dict("NWBUSR") & "," & dict("NWBADM") & ")"

dbConnection.Execute strSQLInsert
strSQLUpdate = "UPDATE Events "

strSQLUpdate = strSQLUpdate & "SET Orig_GroupID = Null, Orig_AttnPeriod = Null, Orig_GroupEventCategoryID = Null "

strSQLUpdate = strSQLUpdate & "WHERE EventID = " & rsTemp(0)

dbConnection.Execute strSQLUpdate
rsTemp.Close : set rsTemp = Nothing