Connecting Tech Pros Worldwide Forums | Help | Site Map

Printing Records

Member
 
Join Date: Aug 2008
Posts: 32
#1: Sep 12 '08
I have a recordset that I am displaying via an ASP. On the web page each record has a textbox next to it, so the user can enter a number for the amount of times that record will need to be displayed for printing. How can I develop a method to loop through each record and display that record based on the number entered in the textbox?

-Gabe

Expand|Select|Wrap|Line Numbers
  1. <%
  2. 'Declare our variables... always a good thing!
  3. Dim cnnSimple    'ADO connection
  4. Dim rstSimple    'ADO recordset
  5. Dim strDBPath    'path to our Access database (*.mdb) file
  6.  
  7. 'Mappath of virtual database file
  8. strDBPath = Server.MapPath("database.mdb")
  9.  
  10. 'Create an ADO connection to connect to the search database
  11. Set cnnSimple = Server.CreateObject("ADODB.Connection")
  12.  
  13. 'This line is for the Access database
  14. cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
  15.  
  16. 'Execute a query using the connection object
  17. Set rstSimple = cnnSimple.Execute("SELECT * FROM labels")
  18. %>
  19. <form action="print.asp" method="post">
  20. <table border="1">
  21.     <tr>
  22.     <th bgcolor="#3D80C2">id</th>
  23.     <th bgcolor="#3D80C2">Location</th>
  24.     <th bgcolor="#3D80C2">Nomenclature</th>
  25.     <th bgcolor="#3D80C2">NSN</th>
  26.     <th bgcolor="#3D80C2">U/P</th>
  27.     <th bgcolor="#3D80C2">Qty</th>
  28.     </tr>
  29.     <%
  30.     Do While Not rstSimple.EOF
  31.         %>
  32.         <tr>
  33.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("id").Value %>&nbsp;</td>
  34.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("bin").Value %>&nbsp;</td>
  35.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("nomen").Value %>&nbsp;</td>
  36.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("nsn").Value %>&nbsp;</td>
  37.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("sell").Value %>&nbsp;</td>
  38.         <td bgcolor="#FFCC00"><p align="center"><input type="text" name="Labelcnt" value="1" size="2"></td>
  39.         </tr>
  40.    <%
  41.     rstSimple.MoveNext
  42.     Loop
  43.    %>
  44. </table>
  45. <input type="submit" value="Submit">
  46. </form>
  47. <%
  48. ' Close our recordset and connection and dispose of the objects
  49. rstSimple.Close
  50. Set rstSimple = Nothing
  51. cnnSimple.Close
  52. Set cnnSimple = Nothing
  53. %>
  54.  

DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#2: Sep 12 '08

re: Printing Records


Hi tsubasa,

You can add another loop inside your Do While Not rstSimple.EOF loop which will repeat each row based on the value of the text box. Read the value of the textbox for each line and use the value to set the number of times you perform the loop. e.g.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Do While Not rstSimple.EOF
  3.     For i = 0 To Request("Labelcnt")
  4.         %>
  5.         <tr>
  6.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("id").Value %>&nbsp;</td>
  7.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("bin").Value %>&nbsp;</td>
  8.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("nomen").Value %>&nbsp;</td>
  9.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("nsn").Value %>&nbsp;</td>
  10.         <td bgcolor="#FFCC00"><%= rstSimple.Fields("sell").Value %>&nbsp;</td>
  11.         <td bgcolor="#FFCC00"><p align="center"><input type="text" name="Labelcnt" value="1" size="2"></td>
  12.         </tr>
  13.         <%
  14.     Next
  15.     rstSimple.MoveNext
  16. Loop
  17. %>
Because your text boxes are named the same on each row the value will appear as a comma delimited list so you'll need to write a bit of logic that either manes the textboxes dynamically (e.g. append a row number to the end of the name) or extracts the correct value from the list for each row.

Let me know how you get on,

Dr B
Reply


Similar ASP / Active Server Pages bytes