Error handling for exiting a record with required fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi-

Can someone give sample codes on how to cancel the data entry routine on a
subform where some required fields were left blank? The error message is
"The field 'FieldX' cannot contain a 'Null' because the Required property for
this field is set to 'True'. Enter a value in this field." Thanks.
 
On the before update event of the subform, you can write the code

If isnull(Me.FieldX) then
msgbox "Field X must be updated"
cancel = true 'wont let the user move to the next record
me.FieldX.SetFocus
End If
 
Ofer, I need something where the user can completely cancel out of an
incomplete data entry. The codes you did below will be helpful for the other
problem. Thanks again.
 
Try this line of code

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
To undo the changes that been made
 
Dim msg, style, response
msg= "Field X must be updated. Do you want to cancel anyawy?"
style - vbyesno
response = (msg,style)

If isnull(Me.FieldX) then
If response = vbyes then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Else
cancel = true 'wont let the user move to the next record
me.FieldX.SetFocus
End If
End If
 
Back
Top