This topic is locked

Get Master info before going to Detail Page

4/4/2009 5:30:00 PM
ASPRunnerPro General questions
Stu author

In a Master/Detail schema the Master List contains a hyperlink to the detail records.
In my Master table I have a field called "Company" but my Detail record hasn't got that field because I can "Show Master Info on Detail Page". But when I want to Add a New Detail record I know my ID Key is automatically transferred to the Detail record but how would I Reference the value of "Company" that was in my Master record that brought me to the Add.
I don't know what Event I can place the code into, I just learnt I can do Code Snippets but don't know where to put some code for this,
My guess is that somewhere I need something like: session("CompanySave")=dict("Company") and then pick up that session variable in the Detail page Add screen.
I guess there is also a dal. way of referencing the value of "Company" by a query on the Master Key value.
Either way telling me what to write and where to put it (nicely!). Would be appreciated. Using v 6.0 for stability.

Stu author 4/6/2009

I decided to work it out and so I have a reply to help others

//////////
'classic link from Detail back to Master Record

'BobSheets is the Master and BobItems is the Detail

'I put this on the Edit Page for BobItems on the Before SQl Query Event
set rs2 = dal.bobitems.Query(strWhereClause,"")
'where bobitems is the table in the page you are on

'and is the Detail Record
'set an SQL string to reference the Master Table by the Foreign Key of the record relating to this page

'rs2("BobLink") is the foreign key that links to BobSheets

'so we set an SQl to reference the Master Table
stSQL="SELECT Contact FROM BobSheets WHERE BobJobNo=" & rs2("BobLink")
'set a variable to the SQl statemement
set rstmp = CustomQuery(stSQL)
Response.Write rstmp("Contact")
'rstmp("Fieldname") is the general reference to any field in your

'query for the Master Table.

'You can now reference any field in the Master Table using the general model

'rstmp("FieldName") where "FieldName" is any real-wrold fieldname in the Master record

'Like "Contact", "Date Arrived", "Materials" etc

//////
Regards,
Stu

(Sorry don't know how to use the Code Snippet thingy!)

In a Master/Detail schema the Master List contains a hyperlink to the detail records.

In my Master table I have a field called "Company" but my Detail record hasn't got that field because I can "Show Master Info on Detail Page". But when I want to Add a New Detail record I know my ID Key is automatically transferred to the Detail record but how would I Reference the value of "Company" that was in my Master record that brought me to the Add.
I don't know what Event I can place the code into, I just learnt I can do Code Snippets but don't know where to put some code for this,
My guess is that somewhere I need something like: session("CompanySave")=dict("Company") and then pick up that session variable in the Detail page Add screen.
I guess there is also a dal. way of referencing the value of "Company" by a query on the Master Key value.
Either way telling me what to write and where to put it (nicely!). Would be appreciated. Using v 6.0 for stability.

jtksmith 4/9/2009

Stu,
I'm still learning ASPRunner, so pleae forgive my ignorance. I've been visiting the forum a lot in the last few days trying to gleam from the many excellent questions and responses. By doing this, I'm trying to learn from those that were here before me as well as trying to avoid asking questions that have already been asked before.
Your question seems very interesting to me but I'm not completely sure what you were trying to accomplish. I see you've already answered your own question and I thought I'd try to put the code into my test project to see what it does. I wonder if I'll know if the code is working or not since I don't fully understand the end goal. I was hoping you could explain a little further explanation of what you were trying to or are accomplishing with this code.
When you say "reference" the value of Company, are saying that you want the value of the Company field to be entered/transferred into the Details table when you add a new Details record? You've acknowledged that the ID is automatically transferred, by which you could display any field from the Master table later on the Details through a Join, at least that is how I understand it. If this is the case, and of course bare in mind I wouldn't be asking this if I understood completely anyway, what would be the purpose of "referencing" the value of Company (out of Master) directly in the Details?
I hope I've posed my question in a way that can be understood because if you've identified a way to do something that might be useful in my own project, I'd definately want to learn from your efforts.
Thank you.

Stu author 4/10/2009

Jeremy,
Not sure I can answer everything but here is another code sample.
'I'm on an Add Page where "Location" is the key in the Detail Table

'and "CompanyAddressCodeValid" is the master table where "Location Code" is the master key
stSQL2="SELECT Company, ad FROM CompanyAddressCodeValid WHERE [Location Code]='" & dict("Location") & "'"
set rstmp = CustomQuery(stSQL2)
'One of the fields on my detail table on the Add Page has a key "Input By" that relates to

'the Master Table "Contacts"
stSQL3="SELECT LastName, FirstName, [Work Phone], EMail FROM Contacts WHERE Seq=" & dict("Input By")
set rstmp3=CustomQuery(stSQL3)
'I am going to send an e-mail where I gather all the elements of the message body from two

'external tables
message =rstmp("Company") & ", " & rstmp("ad") & vbrclf & vbcrlf

message=message & vbcrlf & "Input by: " & rstmp3("Firstname") & " " & rstmp3("Lastname") & vbcrlf
message=message & "Tel: " & rstmp3("Work Phone") & vbcrlf & "Email: " & rstmp3("Email")
message=message & vbcrlf & dict("Type") & ":-" & vbcrlf & dict("Fault or Request") & vbcrlf & "Input: " & now()
'then I do a SendMail

/////////////////////
A Master table might be Company and the Detail table might be Contacts. When I add a Detail Record I wanted to send an e-mail with some of the Master info and Detail info.
I might want to send an E-Mail that says:-
"John Smith has been added as a Contact to the XYZ Company with an e-mail address of jsmith@xyz.com"
"John Smith" and "jsmith@xyz.com" is information in my Detail Record being added but "XYZ Company" is in my Master record. So I have to write a query that uses the common Key between the tables (the "Location Code" in my Master Table but called "Location" in my Detail record). I then use the form set rstmp = CustomQuery(stSQL2) to be a reference to the table and extract the infor using rstmp("TheFieldNameofTheDataIWant")
My BEST advice is to use ASPRunner and select the Wizards like Cars or Events. Get it to make the tables (next page after wizard selection, and then look at the Events. Do that for all the Wizards. There's lots of useful stuff there,
Best Regards,
Stu

Stu,

I'm still learning ASPRunner, so pleae forgive my ignorance. I've been visiting the forum a lot in the last few days trying to gleam from the many excellent questions and responses. By doing this, I'm trying to learn from those that were here before me as well as trying to avoid asking questions that have already been asked before.
Your question seems very interesting to me but I'm not completely sure what you were trying to accomplish. I see you've already answered your own question and I thought I'd try to put the code into my test project to see what it does. I wonder if I'll know if the code is working or not since I don't fully understand the end goal. I was hoping you could explain a little further explanation of what you were trying to or are accomplishing with this code.
When you say "reference" the value of Company, are saying that you want the value of the Company field to be entered/transferred into the Details table when you add a new Details record? You've acknowledged that the ID is automatically transferred, by which you could display any field from the Master table later on the Details through a Join, at least that is how I understand it. If this is the case, and of course bare in mind I wouldn't be asking this if I understood completely anyway, what would be the purpose of "referencing" the value of Company (out of Master) directly in the Details?
I hope I've posed my question in a way that can be understood because if you've identified a way to do something that might be useful in my own project, I'd definately want to learn from your efforts.
Thank you.