Loop through a list in .ASP and post to MS Access

Posted on 2013-11-04
Last Modified: 2013-11-19
I have a ul of text boxes. I want to loop through the list elements and post their values to an Access database. How can I do this in asp?  Here is my current attempt. rsAwards is my recordset, my connection object is named dataCon. I'm looking for a loop that will post all the values of the text boxes within the unordered list. As you can see the list is populated dynamical from the database.

Set dataCon = Server.CreateObject("ADODB.Connection")
Set rsAwards = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM Awards"
rsAwards.Open strSQL, dataCon

<form name="sort_award" action="action_awards.asp?Action=sort&Award_ID=<%=Award_ID%>" method="post">

response.write "<ul id='sortable'>"
  dim i

    While not rsAwards.EOF

      response.write "<li onclick='sort()'><input type='text' id='AwardNum' size='1' value="&i&" ></li>"


response.write "</ul></form>"

Open in new window

Question by:CDCAuman
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

by:Manuel Marienne-Duchêne
ID: 39621849
response.write "<li onclick='sort()'><input type='text' id='AwardNum' size='1' value=""" & i &""" ></li>"

Author Comment

ID: 39621903
Thank you, manumd, for your response.

Unfortunately, that doesn't seem to result in a change.

Here is my loop to post the data

    While not rsEditCourse2.EOF
        for i = 1 to 10
            rsEditCourse2.Fields("Award_Number")(i) = Request.form("AwardNumber")(i)
        i = i + 1

Author Comment

ID: 39622313
Attached is a screenshot of the unordered list written in classic ASP.

The value of the textbox (left) reflects the order of the items within the list. The number in the list (right) is populated from a field inside the database.

Some code has been implemented to allow the user to reorder the list by dragging and dropping the list items. Currently, when this is done, the value inside the textbox (left) changes according to it's new position within the list.

What I would like is by clicking the form's submit button, the number (right) is updated in the database to reflect the new value of it's corresponding textbox (left).

Below is the ASP that creates the list dynamically

<form name="sort_award" action="action_awards.asp?Action=sort&Award_ID=<%=Award_ID%>" method="post">
 end if
 response.write "<ul id='sortable'>"
 dim i

 While not rsAwards.EOF

 response.write "<li onclick='sort()'> &nbsp <input type='text' name='AwardNumber' id='" & rsAwards("Award_Number") & "' size='1' value="&i&" > &nbsp" & rsAwards("Award_Name")
 <a href='edit_awards.asp?Action=edit&Award_ID=<%=rsAwards("Award_ID")%>'>Edit</a>&nbsp;<a class="lb" href='action_awards.asp?Action=delete&Award_ID=<%=rsAwards("Award_ID")%>'>Delete</a></li>

 <input type="submit" value="Sort">

Open in new window


And below is what he has done so far in regards to posting the values of the textbox (left) to the database.

if Request.QueryString("Action") = "sort" then
     'Tell the recordset we are adding a new record to it
     editSQL2 = strSQL & " where Award_ID = " & Request.QueryString("Award_ID")
     rsEditCourse2.Open editSQL2, dataCon
     'Add a new record to the recordset

         dim j
         j = 1
             while j < 10
                 While not rsEditCourse2.EOF
                     rsEditCourse2.Fields("Award_Number") = j
             j = j + 1

     'Write the updated recordset to the database

     'Reset server objects
     Set rsEditCourse2 = Nothing
     Set dataCon = Nothing

 end if 


Open in new window

LVL 33

Accepted Solution

Big Monty earned 500 total points
ID: 39622538
this should be in the classic asp zone, and not the asp .net zone...

to answer your question, it should be relatively simple, as it looks like you're naming your text boxes AwardNumber. Since you're doing that, you will get the data passed over a comma delimited string. So all you would have to do in your save routine would be something like this:

dim AwardNumberList
AwardNumberList = Request.Form("AwardNumber")

'--now split the data into an array
arrAwardNumberList = Split( AwardNumberList, "," )

'-- now loop through the array and save
for each AwardNumber in arrAwardNumberList
    saveToAccessDB( AwardNumber )      '-- your function that does the actual saving

Open in new window


Author Comment

ID: 39660731
Thank you for your response, The_Big_Daddy.  This was quite helpful. By the way, I would have posted in classic asp zone if I could find it... This area was the only .asp area I could find.

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question