tasks come from an external crm, they often come back with an updated status. Also no point in keeping a huge tblTasks as the one where edited records are stored is worth (for analysis purposes)Why are you deleting tasks? Why are they not marked complete and left in the table?
anyways, the update method still allows the same record to end to two different users, I really have no idea why it's still possible so I might need to test your solution
if you feel like wasting more time, this is the query that updates the record, I did split it into 3 different strings as I'm hating the double quotes and the readability & _
feel free to stomp on my sql skills :
Code:
contattiQuery = "SELECT codice " & _
"FROM tabellaSR " & _
"WHERE datalavorazione Is NULL And tipoBacklog = """ & TempVars("backlog") & """ And Substato Like ""*contatto eff"" And DateDiff(""h"", tabellaSR.[Data Aggiornamento], Now()) < 7"
top1query = "SELECT TOP 1 Codice" & _
" FROM tabellaSR" & _
" WHERE dataLavorazione Is NULL" & _
" and codice NOT IN (" & contattiQuery & ")" & _
" and tipoBacklog = """ & TempVars("backlog") & """" & _
" ORDER BY substato LIKE ""*contatto eff"", substato DESC, DateValue(format(tabellaSR.[Data Aggiornamento], ""dd/mm/yyyy"")), timevalue(format(tabellaSR.[Data Aggiornamento], ""hh:mm:ss""))"
lockQuery = "UPDATE tabellaSR " & _
"SET dataLavorazione = """ & lockTime & """, lockedBy = """ & TempVars("Username") & """, stored = ""no"" " & _
"WHERE Codice IN (" & top1query & ")"
dbSR.Execute lockQuery, dbFailOnError
If CBool(dbSR.RecordsAffected) Then
lockedID = DLookup("Codice", "tabellaSR", "dataLavorazione = """ & lockTime & """ AND lockedBy = """ & TempVars("Username") & """")
Else
MsgBox "Non ci sono SR da lavorare, torno al login"
DoCmd.Close acForm, Me.Name, acSaveYes
DoCmd.OpenForm "Login"
Exit Sub