Update problem

Trinb37

Registered User.
Local time
Today, 15:35
Joined
Oct 9, 2003
Messages
23
Hi,
Is there anyone who can help me with this problem? I am at my wits end trying to figure out how to make the query code update the last line inthe table database. This is the code that I used:
Private Sub Return_Click()
Dim strnumber As String
Text34.Value = Val(ClipBoard_GetData)
strnumber = Text34.Value
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdRecordsGoToLast
DoCmd.RunSQL "UPDATE Transactions SET UnitPrice = '" & strnumber & "' WHERE TransactionID =4 "
DoCmd.SetWarnings True
End Sub
The code works fine is just that I can not get it to update the last line. I can update anyother line by just putting a number in the criteria section of the code, but not the last line. I am open to any suggestion. Thank you in advance.
James
 
Either you need to use DAO/ADO to update a record after you position the recordset to it or your update query needs to use criteria to specifically select the row you want to update. You can't attempt to position to a record using DAO/ADO and then expect to run an update query to update that record. The query controls its own movement through a recordset.

BTW, attempting to position to the LAST record will not necessarily get you to the record that you intend. LAST refers to the last record of a recordset which may or may not be the physically or logically last record of a table. Unless a recordset is specifically sorted with an order by clause, its order is arbitrary and any record could end up last.

There is only ONE way to reliably obtain the last record entered into the table and that is to select it by using the Max() function using an autonumber as the operand. If your table does not contain an autonumber (or user-generated ascending sequence number), you cannot reliably obtain the most recently entered record.
 

Users who are viewing this thread

Back
Top Bottom