This topic is locked

Master/Detail Autofill :(

4/26/2007 4:34:10 PM
ASPRunnerPro General questions
M
mlgill author

I have been fooling with this for several days. And cut/pasted several examples of code from the forum to no avail.

I have 2 tables. MAIN and ISSUES. They are joined by field SSN, which is a text field. Both tables also have fields "Emp_Last" and "Emp_First". I have a page that shows MAIN with the details of ISSUES once a SSN in entered.
When I go to add a new ISSUE I need the fields "Emp_Last" and "Emp_First" to automatically fill in with data from the MAIN table.

I was able to get the SSN field in ISSUE to auto fill using Session(strTableName &"_masterkey1") as the default value.
Any and all help will GREATLY be appreciated.
mgill@crawfordadvisors.com

C
clig 4/27/2007

I have been fooling with this for several days. And cut/pasted several examples of code from the forum to no avail.

I have 2 tables. MAIN and ISSUES. They are joined by field SSN, which is a text field. Both tables also have fields "Emp_Last" and "Emp_First". I have a page that shows MAIN with the details of ISSUES once a SSN in entered.
When I go to add a new ISSUE I need the fields "Emp_Last" and "Emp_First" to automatically fill in with data from the MAIN table.

I was able to get the SSN field in ISSUE to auto fill using Session(strTableName &"_masterkey1") as the default value.
Any and all help will GREATLY be appreciated.
mgill@crawfordadvisors.com


  • in your child table set those two default values to session variables - eg. Session("Emp_Last")
  • then add an onload event to the child to get those values from the master table - sample below
    Sub AddOnLoad()

    '** Custom code ****

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

    CN.Open "DSN=NTSS;UID=sa;PWD=pwd"

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

    rs.Open "Select * From MAIN Where SSN = " & GetRequestForm("masterkey"), CN

    Session("Emp_Last") = rs("Emp_Last")

    rs.Close
    End Sub

V
Vladimir 4/27/2007

Hi,
you can do it using ListOnLoad event for Issues table on Events tab:

Sub ListOnLoad()

str = "select Emp_Last,Emp_First from MAIN where SSN='" & Session(strTableName & "_masterkey1") &"'"
Set rsTemp = server.CreateObject("ADODB.Recordset")

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

Session("Emp_First") = rsTemp("Emp_First")
rsTemp.close : set rsTemp = nothing
End Sub



Then set up Session("Emp_Last") and Session("Emp_First") as Emp_Last and Emp_First default values on Visual Editor tab.

M
mlgill author 4/27/2007

Both ways work! THANK YOU SO MUCH!

C
clig 4/30/2007

Hi,

you can do it using ListOnLoad event for Issues table on Events tab:
Then set up Session("Emp_Last") and Session("Emp_First") as Emp_Last and Emp_First default values on Visual Editor tab.


You will likely need to use editid(x) on ListOnLoad

K
KingDean 9/25/2007

Technical information

Error number -2147352567

Error description Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

URL /SRMS_Demo_Maint/Create_Maintenance_Request_add.asp
This is the error i get every time for the following code on the ADD PAGE ONLOAD for Create_Maintenance_Request:
str = "select `Contact Phone` from Users where `User Name` = '" & Session(strTableName & "_masterkey1") &"'"

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

rsTemp.open str, dbConnection

Session("Phone") = rsTemp("Contact Phone")

rsTemp.close : set rsTemp = nothing
if i do the following as it says at the bottom of this post i found it doesn't EOF or BOF at all. It will add the record but nothing happens to my fields.
Here are the joins i have going on
select `work_order_maint`.`WorkID`,

`users`.`User Name`,

`work_order_maint`.`Priority`,

`work_order_maint`.`Created Date`,

`work_order_maint`.`Item Type`,

`work_order_maint`.`LocName`,

`work_order_maint`.`Room`,

`work_order_maint`.`Contact Phone`,

`work_order_maint`.`Closed`,

`work_order_maint`.`Status`,

`m_locations`.`Assigned To`,

`work_order_maint`.`Manufacturer`,

`work_order_maint`.`Approved`,

`work_order_maint`.`Problem Description`
From `work_order_maint`
inner join `m_locations` on `m_locations`.`location` = `work_order_maint`.`locname`
I added this also, thinking it might be a join issue:
inner join `users` on `users`.`user name` = `work_order_maint`.`User Name`
I am trying to have it automatically insert the Contact Phone number in on a record for the User that Typed the Record.

I will not be showing the User Name on the Add Record Screen but i would like to show the Users Contact Number so they could correct if need be. Is This Possible.
MySQL Database, ASPRUNNER 5.0



You will likely need to use editid(x) on ListOnLoad