I am fairly new to Access and am nearing completion of my first database. I was looking for a way to lock the data entry form so that users do not accidentally change data if they are moving between records. I have created a command button and inserted the
vba code below. This code does lock the records upon opening the form, and it does allow me to edit the form when the command button is clicked, and switch back to being locked when clicked again. It is also creating two issues:
- I have two sub forms that are not allowing changes even when the edit button has been pressed. The subforms each have one search combo box, which may be part of the problem. They are each based on a table joining two other tables to offer a drop down
menu.
- The user must click the command button again before moving to the next record, or it will not lock the next record upon opening.
Private Sub Form_Current()
If Me.NewRecord Then
With Me
.cmdEdit.Caption = "Edit"
.cmdEdit.ForeColor = 0
.cmdEdit.FontBold = False
.AllowEdits = True
.cmdEdit.Enabled = False
End With
Else
With Me
.AllowEdits = False
.cmdEdit.Caption = "Edit"
.cmdEdit.ForeColor = 0
.cmdEdit.FontBold = False
.cmdEdit.Enabled = True
End With
End If
End Sub
Private Sub cmdEdit_Click()
Dim cap As String
cap = Me.cmdEdit.Caption
Select Case cap
Case "Edit"
With Me
.AllowEdits = True
.cmdEdit.Caption = "Lock"
.cmdEdit.ForeColor = 128
.cmdEdit.FontBold = True
.Refresh
End With
Case "Lock"
With Me
.AllowEdits = False
.cmdEdit.Caption = "Edit"
.cmdEdit.ForeColor = 0
.cmdEdit.FontBold = False
.Refresh
End With
End Select
End Sub
Any assistance is much appreciated!
<The thread has been moved to the correct category by forum moderator>