Closed Thread
Results 1 to 8 of 8

Thread: Suggestions - ChangedOn field

  1. #1
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Suggestions - ChangedOn field

    Hi All,

    Looking for suggestions / advice.

    I have an asp page where I display a recordset and these records are updated all at once. Well, there are about 185 results, but sometimes only a few records may be changed/updated but all get updated when the form is submitted. If I keep it this way, I was thinking I could add a comment field or checkbox to check for the fields that are changed. Need a way to let me know which records I have already updated.

    Is there a way to only update those records changed and display on the screen a (changed on - field)?

    Code:
    function sZeroCheck(sData)
    	if len(sData) < 1 then
    		sData = 0
    	end if
    	sZeroCheck = sData
    end function
    
    Dim sItem,sMaterial, sMfg1, sMfg2, sMfg3
    Dim rs, sSql
    Dim nCounter
    
    nCounter = 0
    sItem = Request("ItemIDRow" & nCounter)
    
     response.write "First Loop" & sItem & "End"
    do while len(sItem) > 0
    
    
     response.write "Second Loop"
    
    
    sMaterial = Request.Form("MaterialRow" & nCounter)
    sMfg1 = sZeroCheck(Request.Form("Mfg1Row" & nCounter))
    sMfg2 = sZeroCheck(Request.Form("Mfg2Row" & nCounter))
    sMfg3 = sZeroCheck(Request.Form("Mfg3Row" & nCounter))
    %>
    <%
    
    Set rs = Server.CreateObject("ADODB.Recordset")
    
    
    'build SQL
    sSql = "update tblItems set Material = '" & sMaterial & "', ManuDel1 = " & sMfg1 & ", ManuDel2 = " & sMfg2 & ", ManuDel3 = " & sMfg3 & " "
    sSql = sSql & " WHERE ItemID=" & sItem & " "
    'response.write "   " & sSql & "  "
    
    	rs.Open sSql, Conn, 3, 1
    
    nCounter = nCounter + 1
    sItem = Request("ItemIDRow" & nCounter)
    'response.write " NCOunter = " & nCounter
    Loop
    
    Item --- Material ---- Del1 ----- Del2 ----- Del3
    ToolBox--- TB3883 --------1 ---------- 0 ---------- 1
    Kit1 ------- K38220 -------- 0 -------- 0 -------- 0
    Kit2 --------K48201 -------- 1 --------1 -------- 0

    Del1, Del 2, Del3 are textboxes and will get updated as required.
    Last edited by Rebelle; April 2nd, 2008 at 10:18 AM. Reason: adding what form data looks like

  2. #2
    Barn Frequenter BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche's Avatar
    Join Date
    Mar 2008
    Posts
    165
    Rep Power
    4

    Try this code. You can run it as is and see if that is what you are looking for.

    Code:
    <%
    If Request.Form("Submit") <> "" Then
    	For Each Item In Request.Form
    		If Left(Item, 2) = "ID" Then
    			intID = Split(Item, "_")(1)
    			strMaterialRow = Request.Form("MaterialRow_" & intID)
    			strMfg1Row = Request.Form("Mfg1Row_" & intID)
    			strMfg2Row = Request.Form("Mfg2Row_" & intID)
    			strMfg3Row = Request.Form("Mfg3Row_" & intID)
    
    			strSQL = "UPDATE MyTable SET MaterialRow = '" & strMaterialRow & "', " & _
    				"Mfg1Row = '" & strMfg1Row & "', " & _
    				"Mfg2Row = '" & strMfg2Row & "', " & _
    				"Mfg3Row = '" & strMfg3Row & "' " & _
    				"WHERE ID = " & intID
    			response.write strSQL & "<br>"
    		End If
    	Next
    End If
    %>
    <form method="post" action="">
    <table width="500" border="1">
      <tr>
        <td>Update</td>
        <td>Material</td>
        <td>Mfg1</td>
        <td>Mfg2</td>
        <td>Mfg3</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="ID_1"></td>
        <td><input type="text" name="MaterialRow_1"></td>
        <td><input type="text" name="Mfg1Row_1"></td>
        <td><input type="text" name="Mfg2Row_1"></td>
        <td><input type="text" name="Mfg3Row_1"></td>
      </tr>
      <tr>
        <td><input type="checkbox" name="ID_2"></td>
        <td><input type="text" name="MaterialRow_2"></td>
        <td><input type="text" name="Mfg1Row_2"></td>
        <td><input type="text" name="Mfg2Row_2"></td>
        <td><input type="text" name="Mfg3Row_2"></td>
      </tr>
    </table>
    <input type="submit" name="Submit" value="Submit">
    </form>
    
    "You'll never be as perfect as BLaaaaaaaaarche."

  3. #3
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Hi BLaaaaaaaaaarche,

    Ok, having some difficultly here. After our conversation yesterday, I've added a new field for the LastModifiedOn to display the last time the record has been updated. I'm trying to work with the code above to continue to give a checkbox on the screen so if i check the checkbox, only the ones checked should get updated.

    I'm not getting error on the screen when I submit but it's not updating.

    1) Should I have added a field to hold the checkbox value? I have this:
    Code:
    <td><input type="checkbox" name="ID_<%response.write(i)%>"></td>
    
    Thanks again!

  4. #4
    Barn Frequenter BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche's Avatar
    Join Date
    Mar 2008
    Posts
    165
    Rep Power
    4

    The ID_<Value> represents the value, or unique ID, of the record. Why are you using a counter there? You should be using the RS ID when looping through. You will need to provide more code as I can't see what you are working with.
    "You'll never be as perfect as BLaaaaaaaaarche."

  5. #5
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Ok, here is what I have so far....trying to get it to only update which lines are checked.

    Code:
    <%
    If Request.Form("Submit") <> "" Then
    	For Each Item In Request.Form
    		If Left(Item, 2) = "ID" Then
    			intID = Split(Item, "_")(1)
    			strMfg1Row = Request.Form("Mfg1_" & intID)
    			strMfg2Row = Request.Form("Mfg2_" & intID)
    			strMfg3Row = Request.Form("Mfg3_" & intID)
    
    
    			strSQL = "UPDATE tblList SET Mfg1 = '" & strMfg1Row & "', " & _
    				"Mfg2 = '" & strMfg2Row & "', " & _
    				"Mfg3 = '" & strMfg3Row & "' " & _
    				"WHERE ItemID = " & intID
    			response.write strSQL & "<br>"
    		End If
    
    	Next
    End If
    %>
    
    <form method="post" action="">
    <table>
    <TR>
    <th></th>
    <th>Desc.</th>
    <th>Material No.</th>
    <th>Mfg1</th>
    <th>Mfg2</th>
    <th>Mfg3</th>
          </TR>
    </CENTER>
    
    
    <%
    ' scroll to starting record
    i = 1
    
    
    do while not rs.EOF
    	if i > iStopRec then
    		exit do
    	end if
    	
    	i = i + 1
    %>
    
    <TR>      
    <td>
    	<input type=hidden value="<%= rs("ItemID") %>" name="ItemIDRow<%response.write(i)%>">
    	</td>
    
         <td><input type="checkbox" name="ID_<%response.write(i)%>"></td>
    <td><input type="text" name="Description<%response.write(i)%>" value="<%=rs("Description")%>"
    </td>
    <td><input type="text" name="Material<%response.write(i)%>" value="<%=rs("MaterialNum")%>"
    </td>
    
    <TD>
    	<%'Check to see if they are alowed to Edit mfg1 fields
    		If cint(Session("AccessLevel")) >=4 then 
    			%><INPUT CLASS="clrBg" type="text" name="Mfg1Row<%=response.write(i)%>" size="9" maxlength="9" value="<%=rs("Mfg1")%>"</TD><%
    		Else
    			%><INPUT CLASS="clrBg" type="text" name="Mfg1Row<%=response.write(i)%>" size="9" maxlength="9" readonly value="<%=rs("Mfg1")%>"</TD>	<%
    		End if
    	%>
    	</TD>
    <TD>
    	<%'Check to see if they are alowed to Edit mfg2 fields
    		If cint(Session("AccessLevel")) >=4 then 
    			%><INPUT CLASS="clrBg" type="text" name="Mfg2Row<%=response.write(i)%>" size="9" maxlength="9" value="<%=rs("Mfg2")%>"</TD><%
    		Else
    			%><INPUT CLASS="clrBg" type="text" name="Mfg2Row<%=response.write(i)%>" size="9" maxlength="9" readonly value="<%=rs("Mfg2")%>"</TD>	<%
    		End if
    	%>
    	</TD>
    <TD>
    	<%'Check to see if they are alowed to Edit mfg3 fields
    		If cint(Session("AccessLevel")) >=4 then 
    			%><INPUT CLASS="clrBg" type="text" name="Mfg3Row<%=response.write(i)%>" size="9" maxlength="9" value="<%=rs("Mfg3")%>"</TD><%
    		Else
    			%><INPUT CLASS="clrBg" type="text" name="Mfg3Row<%=response.write(i)%>" size="9" maxlength="9" readonly value="<%=rs("Mfg3")%>"</TD>	<%
    		End if
    	%>
    	</TD>
    
    <%
    	i = i + 1
      rs.MoveNext
    loop
    
    rs.Close
    
    %>
    
    No errors but it's not updating...my response.write strSQL outputs:

    Code:
    UPDATE tblList SET Mfg1 = , Mfg2 = , Mfg3 = WHERE ItemID = 2
    

  6. #6
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    As BLaaaaaaaaaarche said above, you shouldn't be using a counter here:
    Code:
    <input type="checkbox" name="ID_<%response.write(i)%>">
    
    Simply plugin the record ID from the recordset:
    Code:
    <input type="checkbox" name="ID_<%=rs("ItemID")%>">
    
    Then, if this checkbox is checked, take the corresponding ItemID and update the record.
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


  7. #7
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Ok, Thank you BLaaaaaaaaaarche and JMurrayhead very much, I am able to update just the records that are checked now.

    But since I am now doing the update on the same page I need some assistance.

    I am use to having this button:
    Code:
    <SCRIPT>
    document.write(new VMLBtn("Save","validate()",90));
    </SCRIPT>
    
    with this for the form, where my update statement on UpdateListFinish.asp:
    Code:
    <FORM name=frmSearch action="UpdateListFinish.asp" method="post" ONSUBMIT="return false;">
    
    Code:
    function validate(){
          if (getIsDataValid()) {
              frmSearch.submit();
          }
      }
    
    
      function getIsDataValid(){
           return true;
      }
    
    But now since I'm using this to submit button:
    Code:
    <input type="submit" name="Submit" value="SAVE">
    
    with this:
    Code:
    <form method="post" action="">
    
    How can I make the below work with the line below work with my original button(VMLBtn)?
    Code:
    If Request.Form("submit") <> "" Then
    

  8. #8
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    disregard previous post. in order for me to use my pretty button, i've moved the update code back to the updateFinish.asp and it's working well so far.

    Thanks again to both of your for your help with this!

Closed Thread

Similar Threads

  1. User Title Suggestions
    By jmurrayhead in forum Suggestions & Feedback
    Replies: 15
    Last Post: March 21st, 2008, 12:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO