I'm using this code to write who's logged onto a workstation to a databse. When they log off, it should record "Logged off".

The problem is, it leaves the old record and when it writes the new one, it missed the username and puts "Logged off" on a record of it's own

I can't seem to work out the edit command.

Any ideas?

Simon

Private Sub Form_Unload(Cancel As Integer)

'write to Who's On file
Dim dbs As Database, rstwhosOn As Recordset
Set dbs = OpenDatabase("user.mdb")
Set rstwhosOn = dbs.OpenRecordset("whosOn")

rstwhosOn.MoveFirst

Do Until rstwhosOn.EOF
If rstwhosOn!workstationName = CurrentComputername Then
rstwhosOn.Delete
End If
rstwhosOn.MoveNext

Loop

rstwhosOn.AddNew
rstwhosOn!workstationName = CurrentComputername
rstwhosOn!UserName = "Logged off"
rstwhosOn.Update

rstwhosOn.Close
dbs.Close

End Sub