I've added a button to the VIEW page and this is the code behind it (On Server section).
Code passes syntax checking, and appears to be ok. However, I'm not sure the code will work.
What I'm trying to do is run a stored procedure in sql(which copies a master table and detail tables with NEW ID's)
, then verify it copied, and then redirect user to VIEW page with the NEW id.
=======================
Function OnServer(params,result,keys)
'Get Current Tmt Plan ID to copy and pass to Stored Procedure
Dim CurTmtPlanID
CurTmtPlanID = Request.form("TmtPlanID")
'Execute SP which copies master and detail records and assigns new TmtPlanID
dbConnection.Execute "exec SP_CopyTmtPlanSTEPONETEST " & CurTmtPlanID
'check if the logging table recorded the successful inserts (and shows old and new tmt plan id's)
Dim NewTmtPlanID
Set rs = dal.Table("LOG_TmtPlansCopied").Query("OldTmtPlanID = " & CurTmtPlanID & " and DateChanged = GetDate() ")
with rs
'If not copied, display error message
If rs.recordcount <> 0 then
Response.write "Tmt Plan was not copied."
Else:
'If copied successfully, redirect user to the VIEW page with the new TmtPlanID
NewTmtPlanID = rs("NewTmtPlanID")
Response.Write "You successfully copied "& OldTmtPlanID & " to " & NewTmtPlanID
Response.Redirect "dbo_RBHS_TmtPlanHDR_4a_View.asp?TmtPlanID=" & NewTmtPlanID
End If
End with
rs.close
End Function ' OnServer