Hope someone can help.
I picked up the code below from the forum.
I am trying to allow a user to 'lock' the record they are viewing so other users don't work on the same record. This code would seem to do everything I wanted. problem is I can't get it to work.
I get an error on this line
DoCmd.RunCommand acCmdSaveRecord ' force access to save current
saying 'the action save record isn't available now'.
I presume this is supposed to update the record/table and switch the boolean field to true and so switch on the flag. I tried afterupdate, beforeupdate and everyother update to no avail. If I set the field to true in the table (manually)the code works and shows the message re "this record is in use" etc but moving to the next record doesn't reset the field to false.
I must be missing something fundamental here but now can't see the wood for the trees.
Would really appreciate some help on this, tried everything I know
Record Locking in Access
Add a column to the table to use as a locking flag. Make it a boolean and call it RecLock.
2. In the current event of the form, check the RecLock.
Code:
If Me.RecLock = True Then
MsgBox "This record is in use by another user, please select another", vbOKOnly
Me.AllowEdits = No
Me.PhoneNumber.Visible = False 'prevent accidental dialing
Else
Me.AllowEdits = Yes
Me.PhoneNumber.Visible = True
End If
3. Add a button to your form and in the click event of the button, add the following:
Code:
Me.RecLock = True
DoCmd.RunCommand acCmdSaveRecord ' force access to save current record
4. In the BeforeUpdate event of your form, add the following:
Code:
Me.RecLock = False
Cheers
RussG
I picked up the code below from the forum.
I am trying to allow a user to 'lock' the record they are viewing so other users don't work on the same record. This code would seem to do everything I wanted. problem is I can't get it to work.
I get an error on this line
DoCmd.RunCommand acCmdSaveRecord ' force access to save current
saying 'the action save record isn't available now'.
I presume this is supposed to update the record/table and switch the boolean field to true and so switch on the flag. I tried afterupdate, beforeupdate and everyother update to no avail. If I set the field to true in the table (manually)the code works and shows the message re "this record is in use" etc but moving to the next record doesn't reset the field to false.
I must be missing something fundamental here but now can't see the wood for the trees.
Would really appreciate some help on this, tried everything I know
Record Locking in Access
Add a column to the table to use as a locking flag. Make it a boolean and call it RecLock.
2. In the current event of the form, check the RecLock.
Code:
If Me.RecLock = True Then
MsgBox "This record is in use by another user, please select another", vbOKOnly
Me.AllowEdits = No
Me.PhoneNumber.Visible = False 'prevent accidental dialing
Else
Me.AllowEdits = Yes
Me.PhoneNumber.Visible = True
End If
3. Add a button to your form and in the click event of the button, add the following:
Code:
Me.RecLock = True
DoCmd.RunCommand acCmdSaveRecord ' force access to save current record
4. In the BeforeUpdate event of your form, add the following:
Code:
Me.RecLock = False
Cheers
RussG