Please visit our sponsor
UNKNOWN '************************************** ' Name: All_Form.ASP ' Description:Multi-function form for ba ' sic navigation, table editing, and recor ' dset paging. This example includes code ' to dynamically build an SQL UPDATE comma ' nd based on changed items on the current ' record. http://adozone.cnw.com/default.htm ' By: Found on the World Wide Web ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None '************************************** &lt;% Option Explicit %&gt; &lt;% Response.Expires=0 %&gt; <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body bgcolor="White" text="Black"> <style> .btn {Width:100%} </style> &lt;% Dim Page ' Local var for page # Dim cn ' Connection object Dim rs ' Recordset object Dim Action ' Button pressed Dim PageSize ' How far to page Dim UpdSQL, MySQL ' String to hold SQL Dim i ' Loop counter Dim item, value ' Used to retrieve changed fields Dim issueUpdate ' After Save button press, any changes to make? Action = Request.Form("NavAction") If Request.Form("Page") &lt;&gt; "" Then Page = Request.Form("Page") Else Page = 1 End If If Request.Form("PageSize") &lt;&gt; "" Then PageSize = Request.Form("PageSize") Else PageSize = 5 End If Set cn = Server.CreateObject("ADODB.Connection") cn.Open Application("guestDSN") ' Get initial recordset Set rs = Server.CreateObject("ADODB.Recordset") MySQL = "SELECT * FROM AUTHORS" rs.PageSize = PageSize rs.Open MySQL, cn, adOpenKeyset, adLockOptimistic Select Case Action Case "Begin" Page = 1 Case "Back" If (Page &gt; 1) Then Page = Page - 1 Else Page = 1 End If rs.AbsolutePage = Page Case "Forward" If (CInt(Page) &lt; rs.PageCount) Then Page = Page + 1 Else Page = rs.PageCount End If rs.AbsolutePage = Page Case "End" rs.AbsolutePage = rs.PageCount Case "Save" ' Grab the proper record, then update ' This routine is hard coded for AU_ID as the key field. ' To alter this to work with another DB Table you will need to ' Use the proper primary key instead of AU_ID. rs.Close MySQL = "SELECT * FROM AUTHORS WHERE au_id = '" & Request.Form("Au_id") & "'" rs.MaxRecords = 1 rs.Open MySQL, cn, adOpenStatic, adLockOptimistic UpdSQL = "UPDATE AUTHORS " issueUpdate = False For i = 0 To (rs.Fields.Count - 1) item = rs.Fields(i).Name value = Request.Form(item) ' Only update items that have changed If (rs(i) &lt;&gt; value) Then If issueUpdate = False Then UpdSQL = UpdSQL & "SET " Else UpdSQL = UpdSQL & "," End If issueUpdate = True Select Case VarType(rs.Fields(i)) ' Determine datatype for proper SQL UPDATE syntax ' NOTE: Not all data types covered Case vbString, vbDate UpdSQL = UpdSQL & item & "='" & value & "'" Case vbNull Case vbInteger UpdSQL = UpdSQL & item & "=" & value Case vbBoolean If value Then UpdSQL = UpdSQL & item & "= 1" Else UpdSQL = UpdSQL & item & "= 0" End If End Select End If Next UpdSQL = UpdSQL & " WHERE au_id = '" & Request.Form("Au_id") & "'" If issueUpdate Then cn.Execute UpdSQL Set rs = cn.Execute(MySQL) End If Case "New" ' response.write "New" rs.AddNew Case "Bookmark" Session("myBookMark") = rs.BookMark Case "Goto" If Not IsNull(Session("myBookMark")) Then rs.BookMark = Session("myBookMark") End If Case Else rs.MoveFirst End Select %&gt; <center> <!-- 2 Column Table --> <!-- 1 Column for Data, 1 for Controls --> <table align="Center" border="1" bgcolor="Navy" bordercolordark="Navy" bordercolorlight="Aqua" bordercolor="Blue"> <!-- Table Header --> <th colspan="2"> <font color="White" size="+2"><center>Navigating Example</center></font> </th> <!-- Main Table Content --> <tr><td> <!-- Nested Table 1 --> <!-- Author Detail --> <form action="/" method="POST"> <table align="Left" border="0" bgcolor="Gray" text="White"> &lt;% For i = 0 To rs.Fields.Count - 1 %&gt; <tr><td><b>&lt;%= rs.Fields(i).Name %&gt;</b></td> <td><input type="text" name="<%= rs.Fields(i).Name %>" value="<%= rs(i) %>"></td> </tr> &lt;% Next %&gt; </table> </td> <td bgcolor="Black" width="100"> <!-- Nested Form 2 --> <!-- Persisted Values --> <input type="Hidden" name="PageSize" value="1"> <input type="Hidden" name="Page" value="<%= Page %>"> <!-- Navigation Buttons --> <input type="Submit" name="NavAction" value="Begin" class="Btn"><br> <input type="Submit" name="NavAction" value="Back" class="Btn"><br> <input type="Submit" name="NavAction" value="Forward" class="Btn"><br> <input type="Submit" name="NavAction" value="End" class="Btn"><p> <input type="Submit" name="NavAction" value="Save" class="Btn"><br> <input type="Submit" name="NavAction" value="New" class="Btn"><p> <input type="Submit" name="NavAction" value="Bookmark" class="Btn"><br> <input type="Submit" name="NavAction" value="Goto" class="Btn"><p> </td> </tr> </table> </form> <p> <!-- Floating Frame --> <iframe width="70%" height="180" src="/" au_id") %>" FrameBorder=1 Scrolling=No&gt; <frame width="70%" height="180" src="/" au_id") %>"&gt; </iframe> </center> </body> </html>