Hi
I have put some validation code in the BeforeUpdate event of a textbox, and the code is
If I deliberately create an activity (other than = 4) of zero time I get the warning message as anticipated but as soon as I click OK I get a run time error 2108 saying I must save the record before using SetFocus.
I have checked other threads and got the Cancel and Undo to put between the message box and the SetFocus but I am still getting the error.
This seems bonkers to me since surely the Cancel and the Undo set the scene for the SetFocus to kick in.
If anyone can help it would be much appreciated.
Thanks and best wishes
I have put some validation code in the BeforeUpdate event of a textbox, and the code is
Code:
If IsNull(Me.txtEndT) Or Me.txtEndT = "" Then
MsgBox "You must enter an end time for the activity", vbOKOnly, "Data validation"
Me.txtEndT.SetFocus
Exit Sub
End If
' If an entry check that it is valid
If CDate(Me.txtDate & " " & Me.txtStartT) > CDate(Me.txtDate1 & " " & Me.txtEndT) Then
MsgBox "The end time for the activity cannot be before the start time", vbOKOnly, "Data validation"
Me.txtEndT.SetFocus
Exit Sub
End If
If Me.txtStartT = Me.txtEndT And Me.cboActivity <> 4 Then
MsgBox "You have set the time for this activity to Zero. Please correct.", vbOKOnly, "Data validation"
Cancel = True
Me.txtEndT.Undo
Me.txtEndT.SetFocus
Exit Sub
End If
I have checked other threads and got the Cancel and Undo to put between the message box and the SetFocus but I am still getting the error.
This seems bonkers to me since surely the Cancel and the Undo set the scene for the SetFocus to kick in.
If anyone can help it would be much appreciated.
Thanks and best wishes