Record Locking - Help!!!

bokarinho

Registered User.
Local time
Today, 15:24
Joined
Mar 31, 2010
Messages
38
Hello,

I need some help here by the experts. Well the issue is the following. I have a form bounded to some records. The enviroment is multi user meaning that 2 users may be use the same record concurrently as access database uses shared mode with default optimistic locks. So far so good. Well i have a user which i have made him a kind of admin meaning that he is the only one in the form that sees a button that can delete the current record. The problem is the following. I want for this user to inform him that when he presses the key to delete the current record, if another user edits the record or views the records (no dirty) at the same time, to inform that user with the username X(X = GetUserName...) is editing the record or something like, user is on the record please contact with him before deleting.. I know that if a user uses tha current record and another user tries to delete the record access informs about that but i want to inform in a custom way so the user can contact the other user to ask him what is doing before deletion. Also i want this to be done without locking the record..
Thanks in advance.
 
If you add a field to the table to store the userid of the person editting the record someone else will see this userid and know that someone is using it.

To do this you need to add an &Edit button to the form. behind this button you can put an update statement which puts the userid of the user in the table. when the user presses cancel or leaves the form or closes the application the userid of this person must be removed in all records
Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Sub CleanUp()

   dim lngUserId as long

   lngUserId = GetLoginName()  ' retrieve the UserId of the currentuser

   Currentdb.execute "update tablename set UserId = 0 where UserId = " & lngUserId

end sub

private sub Cancel_Click()
   CleanUp
end sub
private sub form_Unload()
   CleanUp
end sub

Public Function GetLoginName() As String
    Dim sName As String
    Dim buff As String
    Dim nSize As Long
    
    On Error Resume Next
    
    buff = Space$(MAX_USERNAME)
    nSize = Len(buff)
    
    If GetUserName(buff, nSize) = 1 Then sName = TrimNull(buff)
    
    GetLoginName = sName

End Function
Enjoy!
 

Users who are viewing this thread

Back
Top Bottom