CheckBoxes

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

    #16
    Yes, I want to be able to save the records to a table called labels. The labels table will be used in another part of the program. There a few other functions, but lets get throught this part first.

    -Gabe

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #17
      Originally posted by tsubasa
      Yes, I want to be able to save the records to a table called labels. The labels table will be used in another part of the program. There a few other functions, but lets get throught this part first.

      -Gabe
      OK, if the labels table is in the same db you can reuse the old db connection, but I would open a second recordset:
      Code:
      dim labelsRS
      set labelsRS = server.createobject("adodb.recordset")
      
      labelsRS.open "SELECT * FROM labels", cnnSearch, 2,3
      'opens a recordset that allows you to add, delete, or update records
      
      do until rstSearch.eof
         labelsRS.addNew()
         labelsRS("bin") = rstSearch("bin")
         labelsRS("nomen") = rstSearch("nomen")
         labelsRS("nsn") = rstSearch("nsn")
         labelsRS("sell") = rstSearch("sell")
         labelsRS("oha") = rstSearch("oha")
         labelsRS.Update()
         rstSearch.moveNext
      loop
      Try this, let me know how it goes.

      Jared

      Comment

      • tsubasa
        New Member
        • Aug 2008
        • 64

        #18
        This works great! Hey, Thanks a bunch, you're a really professional. There are some other pages to program, but I want to try and see if I can do those on my own. If I get stuck, would it be alright if I come back and ask for help?

        Again, Thank you!

        -Gabriel

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #19
          Originally posted by tsubasa
          This works great! Hey, Thanks a bunch, you're a really professional. There are some other pages to program, but I want to try and see if I can do those on my own. If I get stuck, would it be alright if I come back and ask for help?

          Again, Thank you!

          -Gabriel
          Sure, and if you become an expert, stick around and answer somebody else's question. Anyway, glad I could help.

          Jared

          Comment

          • tsubasa
            New Member
            • Aug 2008
            • 64

            #20
            Hi Jared,

            As expected,..haha h. I need your assistance. I have created a few pages and now on the page where we initially wrote records to a table called labels. I have been ask to develop a page that brings up all of the records to include a checkbox in case a user would like to check a record for delete. I pretty much used the same code and can see the ID number to include the ON boolean. But when I try to connect to the table so that I can loop through the records and delete the selected record. I get an HTTP 500 internal error which tells me that I am not opening the table for deleting records. Could you please review my code and see what could wrong.

            -Gabe

            Code:
            <%
            for each x in request.form
                response.write x & ": " & request.form(x) & "<br>" & vbNewLine
            next
            
            dim recordsToQuery
            Dim strDBPath  ' path to our Access database (*.mdb) file
            strDBPath = Server.MapPath("database.mdb")
             
            for each x in request.form
               if request(x) = "ON" then
                  recordsToQuery = recordsToQuery & x & ","
               end if
            next
            'recordsToQuery should now be a list of numbers the user selected
            'i.e. "1234,2345,3456,"
             
            'remove trailing comma
            recordsToQuery = left(recordsToQuery, len(recordsToQuery)-1)
             
            query = "SELECT * FROM [labels] WHERE id IN (" & recordsToQuery & ")"
            'then check to make sure this works.  Open the db connection just like 
            'previous and list the records just to make sure you pulled up the right 
            
            
            Set cnnSearch = Server.CreateObject("ADODB.Connection")
            cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
            
            Set rstSearch = cnnSearch.Execute(query)
            
            dim labelsRS
            set labelsRS = server.createobject("adodb.recordset")
             
            labelsRS.open "SELECT * FROM labels", cnnSearch, 2,3
            'opens a recordset that allows you to add, delete, or update records
             
            do until rstSearch.eof
               labelsRS.Delete()
               labelsRS.Update()
               rstSearch.moveNext
            loop
            %>

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #21
              Your code looks OK to me, perhaps you don't need the update line when deleting. My method for deleting looks a bit different. When I delete I only ever delete one record at a time, but here is how you could use my method but delete multiple records using a loop:
              Code:
              on error resume next
              Set cnnSearch = Server.CreateObject("ADODB.Connection")
              cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
              set labelsRS = server.createobject("adodb.recordset")
              
              for each x in request.form
                 if request(x) = "ON" then
                    query = "SELECT * FROM labels WHERE id = " & x
                    labelsRS.open query,cnnSearch,2,3
                    labelsRS.delete
                    if err.number=0 then %>
                       <h2>The entry <%=x%> has been deleted</h2>
                    <% 
                    else %>
                       <h2>There was an error deleting record <%=x%>:</h2>
                       Error #<%=err.number%>: <%=err.description%>
                    <% 
                    end if 
              
                    labelsRS.close
              
                 end if
              next
              Let me know if this works.

              Jared

              Comment

              • tsubasa
                New Member
                • Aug 2008
                • 64

                #22
                Good morning Jared,
                I tired the code and it worked like a champ. Much Thanks!

                -Gabe

                Comment

                • tsubasa
                  New Member
                  • Aug 2008
                  • 64

                  #23
                  Good morning Jared,

                  I have a webpage where the same recordset is being displayed but instead of checkboxes I have textboxes for each record where the user can enter a number in each textbox. The purpose of the page is to print out labels for the selected records based on the number that is entered in the textbox. So if a user was to enter 5, that record would be printed out 5 times. All textboxes are defaulted to 1. How can I develop a way to print each record to inlcude those records who's default value is not 1.

                  -Gabe

                  Code:
                  <%
                  ' Declare our variables... always good practice!
                  Dim cnnSimple  ' ADO connection
                  Dim rstSimple  ' ADO recordset
                  Dim strDBPath  ' path to our Access database (*.mdb) file
                  
                  
                  ' MapPath of virtual database file path to a physical path.
                  ' If you want you could hard code a physical path here.
                  strDBPath = Server.MapPath("database.mdb")
                  
                  
                  ' Create an ADO Connection to connect to the scratch database.
                  ' We're using OLE DB but you could just as easily use ODBC or a DSN.
                  Set cnnSimple = Server.CreateObject("ADODB.Connection")
                  
                  ' This line is for the Access sample database:
                  cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
                  
                  ' We're actually using SQL Server so we use this line instead:
                  'cnnSimple.Open "Provider=SQLOLEDB;Data Source=10.2.2.133;" _
                  '	& "Initial Catalog=samples;User Id=samples;Password=password;" _
                  '	& "Connect Timeout=15;Network Library=dbmssocn;"
                  
                  
                  ' Execute a query using the connection object.  It automatically
                  ' creates and returns a recordset which we store in our variable.
                  Set rstSimple = cnnSimple.Execute("SELECT * FROM labels")
                  
                  
                  ' Display a table of the data in the recordset.  We loop through the
                  ' recordset displaying the fields from the table and using MoveNext
                  ' to increment to the next record.  We stop when we reach EOF.
                  %> </h2>
                  <center>
                  <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"># Labels</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="button" value="Button" name="B1">
                      </form>
                  <%
                  
                  ' Close our recordset and connection and dispose of the objects
                  rstSimple.Close
                  Set rstSimple = Nothing
                  cnnSimple.Close
                  Set cnnSimple = Nothing
                  %>

                  Comment

                  • tsubasa
                    New Member
                    • Aug 2008
                    • 64

                    #24
                    Really quick question for ya.
                    How long did it take you to get this good. I am currently in college pursuing a degree in computer science and I am trying to get a feel on how much time I can expect before someone calls me a salty dog.

                    -Gabe

                    Originally posted by jhardman
                    Sure, and if you become an expert, stick around and answer somebody else's question. Anyway, glad I could help.

                    Jared

                    Comment

                    • jhardman
                      Recognized Expert Specialist
                      • Jan 2007
                      • 3405

                      #25
                      Originally posted by tsubasa
                      Really quick question for ya.
                      How long did it take you to get this good. I am currently in college pursuing a degree in computer science and I am trying to get a feel on how much time I can expect before someone calls me a salty dog.

                      -Gabe
                      hehe.

                      To tell the truth it took a couple hard, live projects that I had to solve or else. Even then, it was interaction with other programmers and answering their questions that helped to refine my techniques and keep the answers on the tip of my tongue.

                      Jared

                      Comment

                      Working...