1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| 'Function used to check if a record is already in use
'*** - Created by JPA on 2000-04-06 (Sales trading) -***************************************************************************************************************
Function checkIfRecordIsLocked(ByVal IDPrimaryKey As Long) As Boolean
Dim oDB As Database
Dim oRS As Recordset
Dim sqlSelection As String
Dim currentDate As Date
Dim sConnectedUser As String
On Error GoTo L_ErrLocked
sqlSelection = "SELECT MaTable.ID, MaTable.DateCreation"
sqlSelection = sqlSelection & vbCrLf & "FROM MaTable"
sqlSelection = sqlSelection & vbCrLf & "WHERE (((MaTable.ID)=" & IDKey & "));"
Set oDB = CurrentDb
Set oRS = oDB.OpenRecordset(sqlSelection, dbOpenDynaset)
With oRS
currentDate = !DateCreation
.Edit
!DateCreation = currentDate
.Update
.Close
End With
checkIfRecordIsLocked = False
L_ExitLocked:
Set oDB = Nothing
Set oRS = Nothing
Exit Function
L_ErrLocked:
sConnectedUser = fnctGetConnectedUserName(Err.Description)
sConnectedUser = IIf(Len(sConnectedUser) > 0, sConnectedUser, "un tiers")
checkIfRecordIsLocked = True
MsgBox "ATTENTION !!!" & vbCrLf & vbCrLf & "Cet enregistrement en cours d'utilisation par " & sConnectedUser & "..." & vbCrLf & vbCrLf & "Il ne peut pas être mis à jour !", 16, "Enregistrement verrouillé"
Resume L_ExitLocked
End Function |
Partager