1

I am trying to update the last record of table Log (the field with the latest TimeAccessed) given that TimeExited is null, and the computername is the same as the "cm" parameter. I have this but get error, "missing semicolon at end of sql statement"

what is wrong??

dbs.Execute "UPDATE Log " _
& "SET TimeExited = " & Format(CloseTime, "\#hh:mm:ss AMPM\#") _
& " WHERE TimeExited is NULL AND ComputerName = '" & cm & "'" _
& " ORDER BY TimeAccessed DESC" _
& " LIMIT 1; "

nothing wrong with first 2 lines, work perfectly fine, it's the last two that give problems

user2006562
  • 75
  • 1
  • 2
  • 9
  • 2
    http://stackoverflow.com/questions/20539095/update-top-1-record-in-table-sql-server – TTT Oct 15 '14 at 17:43

1 Answers1

1

Access SQL doesn't use LIMIT n it uses TOP n, and as mentioned in the other question cited in the comments to your question, you aren't allowed to use TOP in the way you've described. Instead, you'll need to do something along these lines:

UPDATE Log 
SET TimeExited = CloseTime
WHERE TimeExited IS NULL 
    AND ComputerName='r2d2'
    AND TimeAccessed IN
        (
            SELECT TOP 1 TimeAccessed
            FROM Log
            WHERE TimeExited IS NULL 
                AND ComputerName='r2d2'
            ORDER BY TimeAccessed DESC
        )
Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418