Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
STILL NEW TO ASP! Passing a value from one form to a sub-form
Old 06-07-2006, 03:53 PM STILL NEW TO ASP! Passing a value from one form to a sub-form
Average Talker

Posts: 25
Trades: 0
Hi,
I have a form where the user selects an existing record to update status.
They can then link to a sub-form to add comments.
I am trying to retrieve a value from the first form so that it automatically completes one of the fields in the sub-form.
But I'm really not going the right way about it.

Below is my code for the first form (sorry about the length of it!)

Code:
<!-- #Include file = "ADOVBS.INC" -->
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/inetpub/wwwroot/change control.mdb"
set rs=Server.CreateObject("ADODB.recordset")
' first have to get the CCF Number records to fill the drop down....
' Set SQL statement
strSQL = "SELECT * FROM tblform WHERE status = 'Pending'"
 
' Open Recordset Object
rs.Open strSQL,conn
%>
<FORM name="formnumber"> 
<SELECT NAME="qryID" onChange="getFilter(this.form.qryID)">
<OPTION selected>Please Select CCF:
<% Do While Not rs.EOF
 Response.Write ("<OPTION value='" & rs("CCF") & "'>" & rs("CCF"))
 rs.MoveNext
Loop
rs.Close
Set rs=Nothing
%>   
</OPTION> 
</SELECT><BR>
</FORM>
<SCRIPT language="JavaScript">
function getFilter(listitem){
 var object = "";
 var listValue = getListValue(listitem);
 
 document.formnumber.submit(listValue);
 
}

function getListValue(list){
 var listValue="";
 if (list.selectedIndex != -1) {
  listValue = list.options[list.selectedIndex].value;
  }
 return (listValue);
}
</SCRIPT>

<% 
If Request.QueryString("qryID") = "" Then
 Response.Write("Please select a CCF Number from the list.")
Else
 ' Build query
 Set rs = SERVER.CreateObject("ADODB.Recordset")
 ' first have to get the CCF Number to fill the drop down....
 ' Set SQL statement
 strSQL = ("SELECT * FROM tblform LEFT OUTER JOIN tblDiscussion ON tblform.CCF = tblDiscussion.CCFID WHERE tblform.ccf=" & Request.QueryString("qryID") & "  ")   
 ' Open Recordset Object
 rs.Open strSQL, conn, adOpenStatic
 If rs.RecordCount = 0 Then
  Response.Write("No records found for CCF " & Request.QueryString("qryID"))
 Else
  Response.Write("<H3>Details for: CCF " & Request.QueryString("qryID") & "</H3>")
%>  
 
<table border=0 cellspacing=5>
<tr>
<td>CCF Number:</td><td>
<input type="text" name="CCF" size="50" value='<%=RS("CCF")%>' readonly>   
</td></tr>
<tr><td>Type:</td><td>
<input type="text" name="Type" size="50" value='<%=RS("Type")%>' readonly>
</td></tr>
<tr><td>Summary:</td><td>
<input type="text" name="Summary" size="50" value='<%=RS("Summary")%>' readonly>
</td></tr>
<tr><td>Area:</td><td>
<input type="Area" name="Area" size="50" value='<%=RS("Area")%>' readonly>
</td></tr>
<tr><td>Risks:</td><td>
<input type="text" name="Risks" size="50" value='<%=RS("Risks")%>' readonly>
</td></tr>
</table>
</table>
<form name="Approve" method="post" action="approval.asp">
<table height="79">
<tr><td height="7"><font color="#FFFFFF">CCF Number:</font></td><td height="7">
<input type="hidden" name="CCF" size="50" value='<%=RS("CCF")%>'>  
</td></tr>
<tr><td height="22">PCM:</td><td height="22">
<input type="text" name="PCM" size="50" value='<%=RS("PCM")%>'></td>
<td height="22">Action:</td><td height="22">
<select name="PCMAction">
   <option value="<%=RS("PCMAction")%>"><%=RS("PCMAction")%></option>
   <option value="Approved">Approved</option>
   <option value="Rejected">Rejected</option>
   </select></td>
</tr>
   
<tr><td height="38">If Rejected, Please Provide Reason:</td><td height="38">
<input type="text" name="PCMReason" size="50" value='<%=RS("PCMReason")%>'>
</td></tr>
</table>
<hr>
<table height="61">
<tr><td height="22">Reveiwer1</td><td height="22">
<input type="text" name="Approve1" size="50" value='<%=RS("Approve1")%>'></td>
<td height="22">Action:</td><td height="22">
<select name="1Action">
   <option value="<%=RS("1Action")%>"><%=RS("1Action")%></option>
   <option value="Approved">Approved</option>
   <option value="Rejected">Rejected</option>
   </select></td>
</tr>
   
<tr><td height="31">If Rejected, please provide reason:</td><td height="31">
<input type="text" name="1Reason" size="50" value='<%=RS("1Reason")%>'>
</td></tr>
</table>
<hr>
<table HEIGHT="61">
<tr><td height="22">Reveiwer2</td><td>
<input type="text" name="Approve2" size="50" value='<%=RS("Approve2")%>'></td>
<td height="22">Action:</td><td>
<select name="2Action">
   <option value="<%=RS("2Action")%>"><%=RS("2Action")%></option>
   <option value="Approved">Approved</option>
   <option value="Rejected">Rejected</option>
   </select></td>
</tr>
   
<tr><td>If Rejected, please provide reason:</td><td>
<input type="text" name="2Reason" size="50" value='<%=RS("2Reason")%>'>
</td></tr>
</table>
<p align="center">
<input type="submit" name="Submit" value="Update"> </p>
</form>
<hr>
<table height="15" width="676">
<tr><td height="15" width="676">
<font face="Sky InfoText Bd">Assessment Review</font></td></tr>
</table>

   
<%
 
 ' Build a table here
 Response.Write("<TABLE CELLSPACING=3 CELLPADDING=0 COLS=3 WIDTH=750 BGCOLOR=#CCFFFF ALIGN=CENTER>")
 Response.Write("<TR>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=30% BGCOLOR=#0388BB><B>Assessor</B></TD>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=70% BGCOLOR=#0388BB><B>Assessment</B></TD>")
 Response.Write("</TR>")
  
 Do While Not rs.EOF
  Response.Write("<TR>")
  Response.Write("<TD>" & rs("Assess") & "</TD>")
  Response.Write("<TD>" & rs("Discussion") & "</TD>")
  
  Response.Write("</TR>")   
  rs.MoveNext
 Loop
 
 rs.Close
 
 Response.Write("</TABLE>")
 
 Response.Write("<BR>")
 Response.Write("<TABLE ALIGN=CENTER>")
 Response.Write("<form name=Assess method=post action=assess.asp>")
 Response.Write("<input type=submit name=Submit value=Add_Assessment_Review>")
 Response.Write("</form>")
 Response.Write("</TABLE>")
 
 
 End If
 
End If
Set rs=Nothing
%>

<%
conn.Close
Set conn=Nothing
%>
<p align="center">
 
</td></p>


My code for the sub-form is:

Code:
<!-- #Include file = "ADOVBS.INC" -->
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/inetpub/wwwroot/change control.mdb"
set rs=Server.CreateObject("ADODB.recordset")
' Set SQL statement
strSQL = "SELECT * FROM tblDiscussion" 
 
' Open Recordset Object
rs.Open strSQL,conn, adOpenStatic
%>
 

 
<form name="Assess" method="post" action="assessment.asp">
<table>
<tr><td>CCF Number:</td><td>
<input type="text" name="CCFID" size=""50"" value='<%=RS("CCFID")%>' readonly>
</td></tr>
<tr><td>Assessor:</td><td>
<input type="text" name="Assess" size="50" >
</td></tr>
<tr><td>Assessment Review:</td><td>
<input type="text" name="Discussion" size="75" >
</td></tr>
</table>
<input type="submit" name="Submit" value="Submit Assessment">
</form>
<%
Do While Not rs.EOF
rs.MoveNext
Loop
rs.Close
Set rs=Nothing
conn.Close
Set conn=Nothing
%>

In my 1st set of code Request.QueryString("qryID") has the same value as RS("CCF")

In my sub-form, CCFID is related to CCF in my main form.

What I am trying to achieve is the value of Request.QueryString ("qryID") and RS("CCF") (which are the same values) to be automatically passed to the sub-form and becomes the value of <input type="text" name="CCFID" size=""50"" value='<%=RS("CCFID")%>' in the sub-form.

I'm guessing that I need to add another query string in the first form and then retrieve it in the 2nd form.
Any pointers gratefully received!
Thanks,
Lynn
devine is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-21-2006, 09:58 AM Re: STILL NEW TO ASP! Passing a value from one form to a sub-form
etech355's Avatar
Average Talker

Posts: 29
Location: Maryland
Trades: 0
If in the first form you are asking a visitor to select the CCF number.

FORM 1

Code:
<% sql="select distinct ccf from table where criteria = example"
set rs = yourconnectionstring.execute(sql)

<select name="ccf">
<% do while not rs.eof %>
<option value="<%rs("ccf")%>"><%rs("ccf")%></option>
<% rs.movenext
loop
 %>
</select>

<% rs.close
set rs=nothing%>
On the sub form you need to collect and use what they selected.

SUBFORM

Code:
<% 
dim ccf
ccf = request("ccf")
%>
<form name="subform">

Value of CCF from previous form: <input type="text" value="<%=ccf%>">

</form>
Also, since you've already collected the value of CCF and may want to use it again, set CCF as a session variable. Then you can call it up at any time provided you don't close the browser or let it sit too long.

Code:
<%
set session("ccf") = ccf

response.write session("ccf")
%>
Hope this helps.
__________________
Eric

Please login or register to view this content. Registration is FREE
etech355 is offline
Reply With Quote
View Public Profile Visit etech355's homepage!
 
Old 06-30-2006, 12:01 PM Re: STILL NEW TO ASP! Passing a value from one form to a sub-form
Average Talker

Posts: 25
Trades: 0
Hi Eric,
Yes this does help; thank you very much.

I have another problem where I would like to pass the UserID from the login page into several other pages.

I already have this code within the login page:
Code:
Session("userid") = rstLogin.Fields("userid").Value
Could I use this in place of?

Code:
<%
Set Session "UserID" = UserID
response.write session("UserID")
%>
Presumably I would need to insert the code into all the pages that require the login information?

Last edited by devine; 06-30-2006 at 12:07 PM.. Reason: Added existing code
devine is offline
Reply With Quote
View Public Profile
 
Old 06-30-2006, 12:24 PM Re: STILL NEW TO ASP! Passing a value from one form to a sub-form
Average Talker

Posts: 25
Trades: 0
Please ignore my last question...I have solved it, with the help form your original post, so many, many thanks!
devine is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to STILL NEW TO ASP! Passing a value from one form to a sub-form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13458 seconds with 12 queries