This topic is locked

Master Detail

10/5/2006 4:29:23 PM
ASPRunnerPro General questions
C
clig author

Having a brain freeze been away from ASP for a while
I have master table with ID, Project, Customer - in the detail (child) table I also have ID, Project, Customer
Obviously the ID field is filled by the masterkey value when selecting "Add New" - I can't for the life of me pass the Project, Customer fields to the detail table when I select "Add new"
any sample would be appreciated

J
Jane 10/6/2006

Hi,
you can do it using events.

Proceed to the Events tab, select AddOnLoad event and add your code in it.

Here is a sample code:

Sub AddOnLoad()

str = "select * from TableName where ID=" & GetRequestForm("masterkey")

Set rsTemp = server.CreateObject("ADODB.Recordset")

rsTemp.open str, dbConnection
Session("Project") = rsTemp("Project")

Session("Customer") = rsTemp("Customer")

End Sub



where TableName is your actual table name of master table.
Then use Session("Project") and Session("Customer") as default values on the Edit format dialog on the Formatting tab.

C
clig author 10/6/2006

Hi,

you can do it using events.

Proceed to the Events tab, select AddOnLoad event and add your code in it.

Here is a sample code:
where TableName is your actual table name of master table.
Then use Session("Project") and Session("Customer") as default values on the Edit format dialog on the Formatting tab.


merci much! - I had played around with this but was getting errors - looking for a sample - much appreciated!

C
clig author 10/6/2006

Hi,

you can do it using events.

Proceed to the Events tab, select AddOnLoad event and add your code in it.

Here is a sample code:
where TableName is your actual table name of master table.
Then use Session("Project") and Session("Customer") as default values on the Edit format dialog on the Formatting tab.


Success!
_events.asp
<%
Sub AddOnLoad()

'** Custom code ****

set CN = server.CreateObject("ADODB.Connection")

CN.Open "DSN=NTSS;UID=username;PWD=password"

set rs = Server.CreateObject("ADODB.Recordset")

rs.Open "Select Project, Customer, CustomerNumber, LastCall, simsDate, Notes, [SYS Type] AS SYSTYPE From DIALUP1 Where Project = " & cstr(GetRequestForm("masterkey")), CN

Session("Project") = rs("Project")

Session("Customer") = rs("Customer")

Session("CustomerNumber") = rs("CustomerNumber")

Session("LastCall") = rs("LastCall")

Session("simsDate") = rs("simsDate")

Session("Notes") = rs("Notes")

Session("SYSTYPE") = rs("SYSTYPE")

rs.Close
End Sub
%>

  • I am used to adding a lot of my functionality to _aspfunctions.asp such as getting network login id:
    Dim strUserID

    strUserID = Request.ServerVariables("AUTH_USER")

    strUserID = Mid(strUserID,(instr(1,strUserID,"\")+1),len(strUserID))
    I'm curious as to - would you use something like: & Session(strTableName & "_masterkey") where the strTableName would be? - Instead of GetRequestForm("masterkey")?
    Because if you set Dims instead of Session("xxx") in _aspfunctions.asp and test this you get:
    Microsoft VBScript runtime error '800a01a8'
    Object required: 'myRequest'
    /CCAT/CCAT_New_Tickets/include/CCAT_Issues_aspfunctions.asp, line 2217
    Line 2217:
    if myRequest.Exists(key) then

    GetRequestForm = myRequest(key)

    else

    GetRequestForm = Request.QueryString(key)

    end if
    I must be missing something simple... Thanks again!