RE: Submitting data to a database and incrementing the ... - 3/16/2001 20:38:00
Ok here is the sample. Note that you may need to create a folder directly under wwwroot called common and put a copy of adovbs.inc in it. If you search your hard drive you should be able to find this file and make a copy of it. Then place this line of code in between the head tags of your page. <!-- #include virtual="common\adovbs.inc" -->If you don't get any ADO errors then you don't need to worry about this file. <%@ Language=VBScript %> <SCRIPT id=DebugDirectives runat=server language=javascript> // Set these to true to enable debugging or tracing @set @debug=false @set @trace=false </SCRIPT> <FORM name=thisForm METHOD=post> <HTML> <HEAD> <META name=VI60_defaultClientScript content=VBScript> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <%If request("text1")="" then Dim objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=\fpdb\am.mdb;" objConn.Open
Dim RS Set RS = Server.CreateObject("ADODB.Recordset") RS.Open "SELECT * FROM Arrivals", objConn,adOpenStatic,adLockOptimistic RS.MoveFirst%> <% Dim rsVal,mx,FindMax rs.MoveFirst rsVal = rs.Fields("ID").value ' Set mx equal to the numeric portion of the field. mx = Right(rsVal, Len(rsVal) - 3) ' Loop to make sure you have the maximum number. Do While rs.EOF=False rsVal = rs.Fields("ID").value If Right(rsVal, Len(rsVal) - 3) > mx Then mx = Right(rsVal, Len(rsVal) - 3) End If rs.MoveNext Loop ' Increment the maximum value by one and ' combine the text with the maximum number. FindMax = "AR-" & (mx + 1) rs.Close Set rs = Nothing %> <form> <P>Title <INPUT id=text13 name=text1></P> <P>First Name<INPUT id=text2 name=text2></P> <P>Last Name<INPUT id=text3 name=text3></P> <P>Organization<INPUT id=text4 name=text4></P> <P>Postal Code<INPUT id=text5 name=text5></P> <P>ID<INPUT id=text6 name=text6 Value=<%=FindMax%>></P> <INPUT type=submit value="Submit"action="asp page1.asp"> </form> <% Else Dim Conn Set Conn = Server.CreateObject("ADODB.Connection") Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=\fpdb\am.mdb;" Conn.Open Dim myRS Set myRS = Server.CreateObject("ADODB.Recordset") myRS.Open "SELECT * FROM Arrivals", Conn,adOpenStatic,adLockOptimistic myRS.MoveFirst myRS.AddNew myRS("ID")= Request("Text6") myRS("AR_Title") = Request("Text1") myRS("AR_FirstName")= Request("Text2") myRS("AR_LastName")= Request("Text3") myRS("AR_Organization") = Request("Text4") myRS("AR_PostalCode") = Request("Text5") myRS.update Response.Write "Thank you! Your request was received." myRS.Close set myrs = nothing%> <a href="asp page1.asp">Click here to enter another new record</a> <%End if%> </BODY> <% ' VI 6.0 Scripting Object Model Enabled %> <% EndPageProcessing() %> </FORM> </HTML> [This message has been edited by Elecia (edited 03-16-2001).]
[This message has been edited by Elecia (edited 03-16-2001).]
|