I set the field to Null on opening the form so that I get a new "DelayReason" every time the "BookOut " date is changed.
As it is now, the code prompts the user that the field is empty then carries on processing the rest of the code, therefore the user doesn't have an option to populate "DelayReason" !!
Code: Select all
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!DelayReason) Then
MsgBox "Please Enter A Delay Reason", , "Delay"
Me.DelayReason.SetFocus
If MsgBox("Changes Have Been Made To This Record." _
& vbCrLf & vbCrLf & "Do You Want To Save These Changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
'DoCmd.Save
Dim DB As DAO.Database
Dim RST As DAO.Recordset
Set DB = CurrentDb
Set RST = DB.OpenRecordset("tblDelays")
RST.AddNew
RST!JobID = Me.JobID
RST!OriginalDate = tempDate
RST!NewDate = Me.BookOutDate
RST!DelayReason = Me.DelayReason
RST.Update
Set RST = Nothing
Set DB = Nothing
Me.DelayCount = Me.tmpDelayCount + 1
Else
DoCmd.RunCommand acCmdUndo
End If
End If
End Sub