Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Records & Add Blank Rows to a Maximum of 8 2

Status
Not open for further replies.

DebbieC

Programmer
Mar 29, 2001
168
US
I have a form that has one section that has 8 rows on it for a user to input Section Titles and Number of Questions. They have the ability to enter some of the information, save it and return later to add more information. If, for instance, they have only entered 3 rows into this section, I want it to return the rows already entered and then return 5 blank rows for them to add more rows.

I have the first column set up to display the Section Number using a counter. This is what I have so far:

<% do while not objRs3.EOF %>

<% i = i + 1 %>

<tr>
<td>
Section <%= i %> Title:
</td>
<td>
<%= objRs3("SectionTitle") %>
</td>
<td>
Number of Questions:
</td>
<td>
<%= objRs3("Questions") %>
</td>
</tr>

<%
objRs3.movenext()
loop
%>

I'm sure I can use the counter to my advantage to get a count, and add rows until the count is 8 but I'm not sure of how to do that code.

Can anyone help me?
 
Perhaps you can use a For/Next loop like this:

Code:
<% For j = 1 to (8 - i) %>
<tr>
   <td>
     Section <%= j %> Title: 
   </td>
   <td>
     Title for Section <%= j %> Goes Here
   </td>
   <td>
     Number of Questions:
   </td>
   <td>
     # of Questions Goes Here
   </td>
</tr> 
<% Next %>

By doing it this way, if your counter i is equal to 1 then the For/Next goes from 1 to 7, if it is 7 then you go 1 to 1, and if i is equal to 8 you don't loop at all because it would be j = 1 T 0

Or something like this anyway.
 
Same thing, one pass for all:
Code:
For i = 1 To 8
	If not objRs3.Eof Then
		sTitle = objRs3("SectionTitle").value
		sQuestions = objRs3("Questions").value
		objRs3.moveNext
	Else
		sTitle = ""
		sQuestions = ""
	End If
%>
<tr>
   <td>Section <%= i %> Title:</td>
   <td><%= sTitle %></td>
   <td>Number of Questions:</td>
   <td><%= sQuestions %></td>
</tr>	
<%	
Next

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Great!! It's looks like what I need. I'll let you know if I have any problems getting it to work but I doubt it.

Thanks!!!
 
This code worked to create the rows I wanted however now I'm having difficulty saving the information. I had to create text boxes for each one so that the user can change the existing records and add new ones. However I'm having difficulty getting the code to work for both. I can either get it to add or to update but not both.

I changed the names of each one so that I can run a different stored procedure for each. The ones that exist (that will display first in the list) are named "SectionTitle1" & "Questions1". The ones that are new rows displayed are named "SectionTitle2" & "Questions2".

Here is the code I have in the form:

<%
For i = 1 To 8

If not objRs3.Eof Then 'Get Records that Exist

sTitle = "<input type=""text"" name=""SectionTitle1_" & i & """ size=""54"" value=""" & objRs3("SectionTitle") & """>"

sQuestions = "<input type=""text"" name=""Questions1_" & i & """ size=""5"" value=""" & objRs3("Questions") & """>"

objRs3.moveNext

Else 'Add Records that Don't Exist

sTitle = "<input type=""text"" name=""SectionTitle2_" & i & """ size=""54"">"

sQuestions = "<input type=""text"" name=""Questions2_" & i & """ size=""5"">"

End If

%>

<tr>
<td>
Section <%= i %> Title:
</td>
<td>
<%= sTitle %>
</td>
<td>
# of Questions:
</td>
<td>
<%= sQuestions %>
</td>
</tr>

<%
Next
End If
%>

And this is the code I have to save it to the database:

For Each Field In upl.Form
If InStr(Field,"SectionTitle1_")>0 Then
id = Mid(Field,15) SectionTitleNum = id
SectionTitle = Trim(upl.Form(Field))
Questions = Trim(upl.Form("Questions1_" & id))

If SectionTitle <> "" Then
Call UpdateBookletContent(BookletID, SectionTitleNum, SectionTitle, Questions)
Else
End If

Else

If InStr(Field,"SectionTitle2_")>0 Then
id = Mid(Field,15)
SectionTitleNum = id
SectionTitle = Trim(upl.Form(Field))
Questions = Trim(upl.Form("Questions2_" & id))

If SectionTitle <> "" Then
Call AddBookletContent(BookletID, SectionTitleNum, SectionTitle, Questions)

Else
End If

Else
End If

End If

Next

The above code doesn't work correctly. It saves all of the existing records to the values that are in the last row of the existing records. However it does add the new fields correctly.

Does anyone see what I am doing wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top