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:
Expand|Select|Wrap|Line Numbers
- 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
Expand|Select|Wrap|Line Numbers
- 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