This topic is locked

Redirect after adding record passing ID to view

3/22/2007 11:42:12 AM
ASPRunnerPro General questions
D
dlangham author

Hi,
I am trying to redirect after adding a new record to the view page and passing the ID of that new record so its visible in the view page.
I have tried everything I can think of.
Any help would be great.
Rgds

Dale

C
clig 3/22/2007

Hi,

I am trying to redirect after adding a new record to the view page and passing the ID of that new record so its visible in the view page.
I have tried everything I can think of.
Any help would be great.
Rgds

Dale


something like this but for edit - not using getrequestform but rather request:

  • this redirects from list page to edit page for example
  • just look at the url that takes you to the view page and add an event for the add page with a redirect
    Response.Redirect "CCAT_Issues_ME_Close_edit.asp?editid=" & Request("masterkey") & "&editid2=&editid3=&TargetPageNumber=1&todo=view&masterkey=" & Request("masterkey")
  • The add page doesn't really have an editid until saved - I haven't tried this on a parent table...

J
Jane 3/23/2007

Hi,
you can do it using AfterAdd event on the Events tab.

Here is a sample code:

Sub AfterAdd()

str = "select max(IDField) from "TableName"

Set rsTemp = server.CreateObject("ADODB.Recordset")
rsTemp.open str, dbConnection

'** Redirect to another page ****

Response.Redirect "TableName_view.asp?editid1=" & rsTemp(0)
rsTemp.Close : set rsTemp = Nothing
End Sub



where IDField is your primary key, TableName is your actual table name.

D
dlangham author 3/23/2007

Hi,

you can do it using AfterAdd event on the Events tab.

Here is a sample code:
where IDField is your primary key, TableName is your actual table name.


Hi Jane,
Thank you for that. but I had already tried something similar, I am still getting an error, here is my code below where Refernce Number is my PK and Main Table is my table:

Sub AfterAdd()
str = "select max(Reference Number) from "Main Table"

Set rsTemp = server.CreateObject("ADODB.Recordset")
rsTemp.open str, dbConnection

'********** Redirect to another page ************

Response.Redirect "Main_Table_view.asp?editid1=" & rsTemp(0)
rsTemp.Close : set rsTemp = Nothing
End Sub
J
Jane 3/23/2007

Dale,
sorry for my fault.

Here is the correct code:

Sub AfterAdd()

str = "select max([Reference Number]) from [Main Table]"

Set rsTemp = server.CreateObject("ADODB.Recordset")
rsTemp.open str, dbConnection

'** Redirect to another page ****

Response.Redirect "Main_Table_view.asp?editid1=" & rsTemp(0)
rsTemp.Close : set rsTemp = Nothing
End Sub

D
dlangham author 3/23/2007

Thank you Jane,
That worked a treat and I should have noticed it, sorry.
Rgds

Dale