• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Record Lock Problem

Hi Experts:

I'm using the following code which works okay except that after you access a record once and quit, then access that same record again, it's locked like it is suppose to be, however, if you click the save button you get a message box that says the save command is not available, however, you can then edit the record, in other words, it is no longer locked.

If this doesn't make sense let me know and I'll provide more detail.

Private Sub Command6_Click()
On Error GoTo Err_Command6_Click

Me![Locked] = True

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.RunCommand acCmdDataEntry
Exit_Command6_Click:
    Exit Sub

Err_Command6_Click:
    MsgBox Err.Description
    Resume Exit_Command6_Click

End Sub

Private Sub Form_Current()

If IsNull(Me![Locked]) Then Me![Locked] = 0
Me.AllowEdits = Not Me![Locked]

End Sub

Private Sub form_open(Cancel As Integer)
    If Me.RecordsetClone.RecordCount = 0 Then
        DoCmd.OpenForm "Form3"
        Cancel = True
    End If
End Sub

Thanks,

whitesandsbeach
0
whitesandsbeach
Asked:
whitesandsbeach
1 Solution
 
ArjiCommented:
When you add a boolean field to a table, it is always a good idea to do and update query and set the value of the field to something other than Null.  That way you won't have any indeterminate states to test for.  Maybe just simplifying this:

Private Sub Form_Current()

If Me![Locked]
   Me.AllowEdits = Me![Locked]
Else
   Me.AllowEdits = Not Me![Locked]
End Sub
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now