When a form is opened fields are locked. When a new record is added (by pressing an add new record button), fields are unlocked. When the record is saved the fields are then locked again.
However, if a user click the add new record button then the user uses the navagation button at the bottom of the screen to navigate to a previous record, the locked fields are unlocked because a new record was going to be created but in fact never was. How can I prevent this from happening?
My create new record code is as follows:
My Save New Record Code is:
Any assistance would be greatly appreciated.
However, if a user click the add new record button then the user uses the navagation button at the bottom of the screen to navigate to a previous record, the locked fields are unlocked because a new record was going to be created but in fact never was. How can I prevent this from happening?
My create new record code is as follows:
Code:
Private Sub btnAddNewRec_Click()
DoCmd.GoToRecord , , acNewRec
If Me.NewRecord Then
Me.btnSaveNewRec.Visible = True
Me.[txtCoordArea].Locked = False
Me.[Full Name].Locked = False
Me.[Badge ID].Locked = False
Me.[SSN Last 5].Locked = False
Me.[Term Date].Locked = False
Me.[Requester Name].Locked = False
Me.[Supplier].Locked = False
Else
If Not Me.NewRecord Then
Me.[txtCoordArea].Locked = True
Me.[Full Name].Locked = True
Me.[Badge ID].Locked = True
Me.[SSN Last 5].Locked = True
Me.[Term Date].Locked = True
Me.[Requester Name].Locked = True
Me.[Supplier].Locked = True
End If
End If
End Sub
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrorMessage
Dim LResponse As Integer
If Me.Dirty Then LResponse = MsgBox("Do you wish to SAVE your changes?", vbYesNo)
If LResponse = vbYes Then 'User chose Yes - Updated
[txtDateRecordUpdated].Value = Now()
[RecUpdated].Value = True
[txtRecordUpdatedBy].Value = Forms!frmUtility!Full_Name
DoCmd.RunCommand acCmdSave
Else 'User chose No - Not Updated
End If
Me.[txtCoordArea].Locked = True
Me.[Full Name].Locked = True
Me.[Badge ID].Locked = True
Me.[SSN Last 5].Locked = True
Me.[Term Date].Locked = True
Me.[Requester Name].Locked = True
Me.[Supplier].Locked = True
Me.btnSaveNewRec.Visible = False
Exit_Form_BeforeUpdate:
Exit Sub
ErrorMessage:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate
End Sub
Comment