Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update a record using the same page as inserting a record

Status
Not open for further replies.

AssetRecovery

Programmer
Sep 17, 2003
14
US
I have a current page that when I post my information from a form it writes a new record to my database. I like to create a page now that once the record is added it redirects me to that page and the same form that I used to post the new record is now populated with the new records information. Also I need it to have a button that if clicked it will take the values and update the database based on that record id. Here is my current code:

<% @ Language=&quot;VBScript&quot; %>
<% Option Explicit %>
<%
'declare your variables
Dim accountnumber, lastname, firstname, ssn, dob, address, city, st, zip, phonenumber, area, employer, employeraddress, employerphone, cosigner, cosigneraddress, cosignerphone, spouse, pastdue, priorrepo, priordate, agency, agent, agencyphone, agentextension, agencyfax, vehicleyear, vehiclemake, vehiclemodel, vehiclecolor, vin, license, totalcharges, deliveredto, assigneddate, storagein, storageout, storagedays, repoagent, statuscode, accountstatus, ros, roc, cdb, othercollateral, dailynotes, housenotes
Dim sConnString, connection, sql_insert


' Receiving values from Form, assign the values entered to variables
accountnumber = Request.Form(&quot;accountnumber&quot;)
lastname = Request.Form(&quot;lastname&quot;)
firstname =Request.Form(&quot;firstname&quot;)
ssn =Request.Form(&quot;ssn&quot;)
dob =Request.Form(&quot;dob&quot;)
address =Request.Form(&quot;address&quot;)
city =Request.Form(&quot;city&quot;)
st =Request.Form(&quot;state&quot;)
zip =Request.Form(&quot;zip&quot;)
phonenumber =Request.Form(&quot;phonenumber&quot;)
area =Request.Form(&quot;area&quot;)
employer =Request.Form(&quot;employer&quot;)
employeraddress =Request.Form(&quot;employeraddress&quot;)
employerphone =Request.Form(&quot;employerphone&quot;)
cosigner =Request.Form(&quot;cosigner&quot;)
cosigneraddress =Request.Form(&quot;cosigneraddress&quot;)
cosignerphone =Request.Form(&quot;cosignerphone&quot;)
spouse =Request.Form(&quot;spouse&quot;)
pastdue =Request.Form(&quot;pastdue&quot;)
priorrepo =Request.Form(&quot;priorrepo&quot;)
priordate =Request.Form(&quot;priordate&quot;)
agency =Request.Form(&quot;agency&quot;)
agent =Request.Form(&quot;agent&quot;)
agencyphone =Request.Form(&quot;agencyphone&quot;)
agentextension =Request.Form(&quot;agentextension&quot;)
agencyfax =Request.Form(&quot;agencyfax&quot;)
vehicleyear =Request.Form(&quot;vehicleyear&quot;)
vehicleyear=Request.Form(&quot;vehicleyear&quot;)
vehiclemake =Request.Form(&quot;vehiclemake&quot;)
vehiclemodel =Request.Form(&quot;vehiclemodel&quot;)
vehiclecolor =Request.Form(&quot;vehiclecolor&quot;)
vin =Request.Form(&quot;vin&quot;)
license =Request.Form(&quot;license&quot;)
totalcharges =Request.Form(&quot;totalcharges&quot;)
deliveredto =Request.Form(&quot;deliveredto&quot;)
assigneddate =Request.Form(&quot;assigneddate&quot;)
storagein =Request.Form(&quot;storagein&quot;)
storageout =Request.Form(&quot;storageout&quot;)
storagedays =Request.Form(&quot;storagedays&quot;)
repoagent =Request.Form(&quot;repoagent&quot;)
statuscode =Request.Form(&quot;statuscode&quot;)
accountstatus =Request.Form(&quot;accountstatus&quot;)
ros =Request.Form(&quot;ros&quot;)
roc =Request.Form(&quot;roc&quot;)
cdb =Request.Form(&quot;cdb&quot;)
othercollateral =Request.Form(&quot;othercollateral&quot;)
dailynotes =Request.Form(&quot;dailynotes&quot;)
housenotes =Request.Form(&quot;housenotes&quot;)

'declare SQL statement that will query the database
sql_insert = &quot;insert into repo (AccountNumber, LastName, FirstName, Address, City, State, Zip, Area, AccountStatus, SSN, DOB, PhoneNumber, Spouse, Employer, EmployerAddress, EmployerPhone, CoSigner, CosignerAddress, CosignerPhone, PastDue, PriorRepo, PriorDate, ROS, ROC, CDB, VehicleYear, VehicleMake, VehicleModel, VehicleColor, VIN, License, Agency, Agent, AgencyPhone, AgentExtension, AgencyFax, AssignedDate, TotalCharges, DeliveredTo, StorageIn, StorageOut, StorageDays, RepoAgent, StatusCode, OtherCollateral, DailyNotes, HouseNotes) values ('&quot; & accountnumber & &quot;', '&quot; & lastname & &quot;', '&quot; & firstname & &quot;', '&quot; & address & &quot;', '&quot; & city & &quot;', '&quot; & st & &quot;', '&quot; & zip & &quot;', '&quot; & area & &quot;', '&quot; & accountstatus & &quot;', '&quot; & ssn & &quot;', '&quot; & dob & &quot;', '&quot; & phonenumber & &quot;', '&quot; & spouse & &quot;', '&quot; & employer & &quot;', '&quot; & employeraddress & &quot;', '&quot; & employerphone & &quot;', '&quot; & cosigner & &quot;', '&quot; & cosigneraddress & &quot;', '&quot; & cosignerphone & &quot;', '&quot; & pastdue & &quot;', '&quot; & priorrepo & &quot;', '&quot; & priordate & &quot;', '&quot; & ros & &quot;', '&quot; & roc & &quot;', '&quot; & cdb & &quot;', '&quot; & vehicleyear & &quot;', '&quot; & vehiclemake & &quot;', '&quot; & vehiclemodel & &quot;', '&quot; & vehiclecolor & &quot;', '&quot; & vin & &quot;', '&quot; & license & &quot;', '&quot; & agency & &quot;', '&quot; & agent & &quot;', '&quot; & agencyphone & &quot;', '&quot; & agentextension & &quot;', '&quot; & agencyfax & &quot;', '&quot; & assigneddate & &quot;', '&quot; & totalcharges & &quot;', '&quot; & deliveredto & &quot;', '&quot; & storagein & &quot;', '&quot; & storageout & &quot;', '&quot; & storagedays & &quot;', '&quot; & repoagent & &quot;', '&quot; & statuscode & &quot;', '&quot; & othercollateral & &quot;', '&quot; & dailynotes & &quot;', '&quot; & housenotes & &quot;')&quot;

'define the connection string, specify database
'driver and the location of database
sConnString=&quot;DRIVER={Microsoft Access Driver (*.mdb)};&quot; & _
&quot;DBQ=&quot; & Server.MapPath(&quot;data/repo_2002.mdb&quot;) & &quot;;&quot;


'create an ADO connection object
Set connection = Server.CreateObject(&quot;ADODB.Connection&quot;)

'Open the connection to the database
connection.Open(sConnString)

'execute the SQL
connection.execute(sql_insert)

' Done. Close the connection object
connection.Close
Set connection = Nothing
response.redirect &quot;viewform.asp&quot;
%>
 
Well i'll give you an simple example that should make your work much much easyer and no more problems with quoted string and types.
This is an example code to make it work you must work with valid connection,table and fields.

Code:
sql=&quot;&quot;
con.Open &quot;you connection string&quot;
if Request(&quot;curentfield&quot;)<>&quot;&quot; then
'we have an update
 sql=&quot;select * from myTable where id_mytable=&quot;&Request(&quot;curentfield&quot;)
 rs.Open sql,con,3,3
 rs.Edit
else
'we have an add
 sql=&quot;select top 1 * from myTable&quot;
 rs.Open sql,con,3,3
 rs.AddNew
end if
'then start to fill out your fields in the rs object
rs(&quot;field1&quot;)=Request(&quot;field1&quot;)
rs(&quot;field2&quot;)=Request(&quot;field2&quot;)
rs(&quot;field3&quot;)=Request(&quot;field3&quot;)
...
rs(&quot;fieldn&quot;)=Request(&quot;fieldn&quot;)

rs.Update

and this should be it.

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top