473,395 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Taking control of a record

Hi All,
I have created a multi-user application at work which is working
perfectly apart from a small problem which I believe to more a of a user
issue (maybe some will set me straight on that one). I have set the 'Default
Record Locking' option to 'Edited Record' in the hope that if someone tries
to edit a record someone has open, they would not be able to do so.

After a little testing, I found this not to be the case. Instead, if 2 users
are editing a record at the same time and one of them moves to another
record, the user moving to a new record is presented with a 'Write Conflict'
message giving them 3 options of:
* Save Record
* Copy to clipboard
* Drop changes

I wish to eliminate this happening by making the user "Take Control" of the
record before they can begin to edit it.

I have started this process by adding a text field to the underlying table
called 'LockedBy'. I have also set the AllowEdits option of the form to
False.

To edit the record, the user must first click a command button which checks
if the LockedBy field is Null. If it is, it updates the field with their
UserID (I have a custom login form combined with Access built in security)
and sets the AllowEdits option to True.

Now, should another user try to take control of the record, a check is
performed to see if the field is null (combined with a check to see if the
LockedBy field matches the current user), if it isn't, they receive a
message box stating that they cannot edit the record until xxxxxxx releases
control of it.

This works perfectly except for one problem. Once the user that has control
of the record is finished with it, I need to make sure they release control.
This is what I can't figure out how to do.

I am not a programmer and have only recently started to dabble. Below is the
code I am using. If anyone has any better suggestions on how to achieve the
same result, I'd be very grateful.

TIA,

Mark

Private Sub cmd_TakeControl_Click()

'If the record is locked by someone other than current user,
If Me.Locked.Value = True And Me.LockedBY.Value <>
Displayname(Forms!frm_userlogin!txt_UserID) Then
MsgBox "This record is currently locked by " & Me.LockedBY.Value &
vbCrLf & _
"You cannot edit this record until they release control of it",
vbInformation, "Record Locked"
Me.cmd_TakeControl.Caption = "Take Control"
Me.AllowEdits = False

'If the record is lockedby the current user, determine the command caption
ElseIf Me.Locked.Value = True And Me.LockedBY.Value =
Displayname(Forms!frm_userlogin!txt_UserID) Then
'the current user has the record locked, determine if they clicked to
release or take control
If Me.cmd_TakeControl.Caption = "Take Control" Then
Me.AllowEdits = True
Me.Locked = True
Me.LockedBY.Value = Displayname(Forms!frm_userlogin!txt_UserID)
Me.cmd_TakeControl.Caption = "Release Control"
Else
Me.AllowEdits = False
Me.Locked = False
Me.LockedBY.Value = Null
Me.cmd_TakeControl.Caption = "Take Control"
End If

Else 'No-one has control of the record

Me.AllowEdits = True
Me.Locked = True
Me.LockedBY.Value = Displayname(Forms!frm_userlogin!txt_UserID)
If Me.Dirty = True Then
Me.Dirty = False
End If

Me.cmd_TakeControl.Caption = "Release Control"
End If
End Sub
May 23 '06 #1
2 2411
Good news and bad news, I think.

Good: Use the form's afterupdate event to clear whatever you set up in the
takecontrol code.

Bad: Your problem may be due to the fact that in Access (actually in the Jet
Engein) record locking is not exactly record locking. Up through Access
2000 what is called "record locking" was actuall "page locking". All the
records on a single page were locked, rather than being able to truly lock a
single record, as you can in SQL Server/Oracle/etc. I don't find any
information that says this has changed in later editions.

---------------------------------------------------------------------------------------------

Our solution was to move to unbound forms, which meant using a function to
create a recordset, load the data into the unbound controls on a form, then
close the recordset. A Save button fires the inverse function to write data
out of the controls back into a writeable recordset created only for the
instant it takes to write the data.

The whole library of routines was less than 400 lines of code, including
logging changes to our own table of changes to keep track of who changed
what field from what to what when.

May 23 '06 #2
Hi again,
I thought I would post the solution I have come up with which may be
ugly but it works.....

I created an unbound text box and check box on the form footer which are
both set to Visible = False.
When the user takes control of a record, the check box value is updated to
True and the text box value is updated to the records ID.
Using the OnCurrent event of the form, I have a check to see if the value of
the check box is True. If it is, the current Record ID is compared with the
value of the unbound textbox. If they differ, the user is alerted that they
have left a record locked and an ApplyFilter command is run using the
unbound textbox value as the criteria.

I also have the same checks in the form's Unload event should they just
close the form after an edit.

As I said, it may be ugly but it works!!!!

Many thanks,

Mark
"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:he*************@newsfe2-win.ntli.net...
Hi All,
I have created a multi-user application at work which is working
perfectly apart from a small problem which I believe to more a of a user
issue (maybe some will set me straight on that one). I have set the 'Default
Record Locking' option to 'Edited Record' in the hope that if someone tries
to edit a record someone has open, they would not be able to do so.

After a little testing, I found this not to be the case. Instead, if 2 users
are editing a record at the same time and one of them moves to another
record, the user moving to a new record is presented with a 'Write Conflict'
message giving them 3 options of:
* Save Record
* Copy to clipboard
* Drop changes

I wish to eliminate this happening by making the user "Take Control" of the
record before they can begin to edit it.

I have started this process by adding a text field to the underlying table
called 'LockedBy'. I have also set the AllowEdits option of the form to
False.

To edit the record, the user must first click a command button which checks
if the LockedBy field is Null. If it is, it updates the field with their
UserID (I have a custom login form combined with Access built in security)
and sets the AllowEdits option to True.

Now, should another user try to take control of the record, a check is
performed to see if the field is null (combined with a check to see if the
LockedBy field matches the current user), if it isn't, they receive a
message box stating that they cannot edit the record until xxxxxxx releases
control of it.

This works perfectly except for one problem. Once the user that has control
of the record is finished with it, I need to make sure they release control.
This is what I can't figure out how to do.

I am not a programmer and have only recently started to dabble. Below is the
code I am using. If anyone has any better suggestions on how to achieve the
same result, I'd be very grateful.

TIA,

Mark

Private Sub cmd_TakeControl_Click()

'If the record is locked by someone other than current user,
If Me.Locked.Value = True And Me.LockedBY.Value <>
Displayname(Forms!frm_userlogin!txt_UserID) Then
MsgBox "This record is currently locked by " & Me.LockedBY.Value &
vbCrLf & _
"You cannot edit this record until they release control of it",
vbInformation, "Record Locked"
Me.cmd_TakeControl.Caption = "Take Control"
Me.AllowEdits = False

'If the record is lockedby the current user, determine the command caption
ElseIf Me.Locked.Value = True And Me.LockedBY.Value =
Displayname(Forms!frm_userlogin!txt_UserID) Then
'the current user has the record locked, determine if they clicked to
release or take control
If Me.cmd_TakeControl.Caption = "Take Control" Then
Me.AllowEdits = True
Me.Locked = True
Me.LockedBY.Value = Displayname(Forms!frm_userlogin!txt_UserID)
Me.cmd_TakeControl.Caption = "Release Control"
Else
Me.AllowEdits = False
Me.Locked = False
Me.LockedBY.Value = Null
Me.cmd_TakeControl.Caption = "Take Control"
End If

Else 'No-one has control of the record

Me.AllowEdits = True
Me.Locked = True
Me.LockedBY.Value = Displayname(Forms!frm_userlogin!txt_UserID)
If Me.Dirty = True Then
Me.Dirty = False
End If

Me.cmd_TakeControl.Caption = "Release Control"
End If
End Sub

May 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Ideasman | last post by:
Hi I have a made a script that process normals for a flat shaded 3D mesh's. It compares every vert with every other vert to look for verts that can share normals and It takes ages. I'm not...
6
by: Bruce Rusk | last post by:
I'm using Stephen Lebans' RTF2 control in a report, and have discovered what may be a slight bug in it. I have a lot of non-Western language (Chinese) text in my RTF field, and such records get...
2
by: John Hargrove | last post by:
I'm having trouble setting decimal place values in the results field of a sample management database I'm building for an environmental testing laboratory. The degree of sensitivity varies among...
7
by: vindaloo1 | last post by:
I'm using Access 2000 and I have a main form and a subform. When a control on the subform is updated I am trying to update a control on the mainform. But instead of updating the control on the...
2
by: MLH | last post by:
I have a form based on a table. The table has a Yes/No field. Its an A97 table. The form has a button that updates the value in the control from No to Yes for the record currently being edited. ...
2
by: JJ | last post by:
OK - I asked this earlier but thought I'd solved it. Clearly not. I have a control that I need to display text from an sql database. The control is being used as a web part so can be placed on a...
7
by: Computer Guru | last post by:
Hi, Pardon the unclear/verbose subject, I just can't think of another way of phrasing it. Basically, I can assign the (for instance) "Location" property of a picture box to a data-bound item....
2
by: angi35 | last post by:
I hope this is an easy question for someone out there. In Access 2000…I have a MainForm with a tab control (MAIN TABS) with 7 tabs. Within each tab is a SubForm. Within each SubForm is a tab...
6
by: Gouri.Mahajan7 | last post by:
Hello, When I press the button on the web page I am loading the user control on the web page. This user control is invoking some methods of the web service. The control on the web page is loaded...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.