Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

update record with out updating a previous record

record 1 is created and saved to the table. for customer A
4 hours later customer A comes back and another record is created (record 2). before customer A leaves, they remember they did something else and needs record 2 updated.
now since customer A has beed here 2 times he has 2 records time stamped with the current date but different times. How can you update the record 2 with out updateing record 1?

EX.

Records are saved with customers A's id number and a timestamp that is created by a varible

the sql string to update the record

sql = "UPDATE Table1 SET Notes = ' " & txtnotes & " ' WHERE CustID = " & lblCustID & " AND SampleDate = " & savedate & " "

ex. currentdate(0) is the date 1/1/1111 currentdate(1) is the time 12:00:00
savedate = lblCurrentDate(0).Caption & " " & lblCurrentDate(1).Caption

the savedate is saved to the table as follows --> 4/14/2006 10:25:07

At this point I get a datatype mismatch error if I drop the time and leave the date it updates the record but also updates any previous record for that day.
[1149 byte] By [jim12345] at [2007-11-11 8:29:02]
# 1 Re: update record with out updating a previous record
i resolved this problem by doing the following
add a field to your database named recNumber and field type to autonumber

run a sql query on the table for recNumber
Dim sqlFindLast as String
Dim LastRec as Interger
sqlFindLast = SELECT recNumber FROM Table1 WHERE custID = ;
rs.open sqlFindLast
rs.MoveLast
LastRec = rs(0)

now update the table with

sqlupdateNotes = "UPDATE Table1 SET Notes = ' " & txtnotes & " ' WHERE CustID = " & lblCustID & " AND recNumber = " & LastRec & " "

This will update the last record in the table by customer ID

This works because of the auto number type for the recNumber field.
jim12345 at 2007-11-11 17:25:32 >