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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying values from an existing record into a new record

Status
Not open for further replies.

david7777777777

Programmer
Sep 26, 2001
417
US
I have ASP pages talking to SQL 2000 database. Here's a simple version of the tbl_Shipments table:

TrackingNumber PK
DateSent
DateReceived
Tape01
Tape02
Tape03

I have a query page that displays records according to their TrackingNumber value. I'd like the user to be able to click a "MakeNewShipment" button, which would take all of the values from the current, existing record being displayed in this query page and "throw" all of the values(except the TrackingNumber)into corresponding DTC's on a "NewShipment' page, where the user would only have to re-enter the new Tracking number for this shipment/box. I thought about throwing the existing record in to the editable grid and simply having the user edit the TrackingNumber that way, but I haven't figured out how to allow the user to be able to delete/reset the ReceivedDate field so it can be re-enterd when the shipment is received again. Make sense? Thanks for any clues. This trick is completely new territory for me.
 
Add new records can indeed be a bit of a pain. Here are a couple of ideas:
1. Use unbound text boxes, and populate their values in the thispage_onenter or pbAddUsing_onclick event from the current recordset row, or from parameters passed to the form. When the user clicks the Save button, then pass the values of the text boxes into a insert clause or stored procedure (use the DataEnvironment to add a suitable command with parameters for each column - ie "INSERT INTO X(c1, c2) values (?, ?)" ).

2. Use bound text boxes, gather the default values (current row columns) into variables, do a rsRecordset.AddNew, set the textbox values to the variables gathered earlier. On the Save, just do an rsRecordset.update - though this MAY not work.

3. combine methods 1 and 2 - use bound text boxes. User performs the edits but presses a 'Save As New Entry' button. This then passes the textbox values to a INSERT clause or stored procedure.

If you have a stored procedure or INSERT clause with variables as a command in the DataEnvironment, then your page code is just:

sub pbSaveAsNew_OnClick()
thisPage.createDE
'execute a command called addNewShipment
' that takes 2 parameters
DE.addNewShipment txtDateSent.value, txtDateRecieved.value

'refresh recordset to include the new row
' and to refresh the textboxes
rsShipments.requery

end sub

the command addNewShpment could be a stored procedure which auto-generated the TrackingNumber key value, or an INSERT clause - but then the tracking number would have to be supplied. (Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top