Error handling for exiting a record with required fields

D

danlin

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.
 
O

Ofer

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
 
D

danlin

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.
 
O

Ofer

Try this line of code

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
To undo the changes that been made
 
D

danlin

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
 
Top