gianniskar
New member
- Local time
- Today, 20:40
- Joined
- Feb 27, 2020
- Messages
- 24
hi.I have my access tables to sql server and i have this code to "log" forms or reports when closing or opening in sql server.This function working when table is on local pc but when is in sql server and i am trying to close form i have this error "Run-time error '3020': Update or CancelUpdate without AddNew or Edit"
Code:
Function LogAction(obj As Object, Optional LastID As Long)
With CurrentDb.OpenRecordset("tblLog", dbOpenDynaset, dbSeeChanges)
If LastID Then
LastID = IIf(obj.Tag <> vbNullString, obj.Tag, -1)
obj.Tag = vbNullString
.MoveFirst
.FindFirst "LogID = " & LastID
'
If Not .NoMatch Then
.Edit
.Fields("CloseDateTime") = Format(Now, "yyyy-MM-dd hh:mm:ss")
End If
Else
.AddNew
LastID = Nz(.Fields("LogID"), 0)
obj.Tag = LastID
.Fields("OpenDateTime") = Format(Now, "yyyy-MM-dd hh:mm:ss")
.Fields("DocName") = obj.name
.Fields("ComputerName") = Environ("COMPUTERNAME")
.Fields("WinUser") = Environ("USERNAME")
.Fields("AppUser") = Application.CurrentUser
End If
.Update
.Close
End With
End Function
Code:
Private Sub Form_Close()
LogAction Me, 1
End Sub
Private Sub Form_Load()
LogAction Me, 0
End Sub