Printing Records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tsubasa
    New Member
    • Aug 2008
    • 64

    Printing Records

    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

    Code:
    <%
    'Declare our variables... always a good thing!
    Dim cnnSimple	'ADO connection
    Dim rstSimple	'ADO recordset
    Dim strDBPath	'path to our Access database (*.mdb) file
    
    'Mappath of virtual database file
    strDBPath = Server.MapPath("database.mdb")
    
    'Create an ADO connection to connect to the search database
    Set cnnSimple = Server.CreateObject("ADODB.Connection")
    
    'This line is for the Access database
    cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
    
    'Execute a query using the connection object
    Set rstSimple = cnnSimple.Execute("SELECT * FROM labels")
    %>
    <form action="print.asp" method="post">
    <table border="1">
        <tr>
        <th bgcolor="#3D80C2">id</th>
        <th bgcolor="#3D80C2">Location</th>
        <th bgcolor="#3D80C2">Nomenclature</th>
        <th bgcolor="#3D80C2">NSN</th>
        <th bgcolor="#3D80C2">U/P</th>
        <th bgcolor="#3D80C2">Qty</th>
        </tr>
        <%
        Do While Not rstSimple.EOF
            %>
            <tr>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("id").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("bin").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("nomen").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("nsn").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("sell").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><p align="center"><input type="text" name="Labelcnt" value="1" size="2"></td>
            </tr>
       <%
        rstSimple.MoveNext
        Loop
       %>
    </table>
    <input type="submit" value="Submit">
    </form>
    <%
    ' Close our recordset and connection and dispose of the objects
    rstSimple.Close
    Set rstSimple = Nothing
    cnnSimple.Close
    Set cnnSimple = Nothing
    %>
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    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.

    Code:
    <%
    Do While Not rstSimple.EOF
        For i = 0 To Request("Labelcnt")
            %>
            <tr>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("id").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("bin").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("nomen").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("nsn").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><%= rstSimple.Fields("sell").Value %>&nbsp;</td>
            <td bgcolor="#FFCC00"><p align="center"><input type="text" name="Labelcnt" value="1" size="2"></td>
            </tr>
            <%
        Next
        rstSimple.MoveNext
    Loop
    %>
    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

    Comment

    Working...