Trapping for Error 3314

  • Thread starter Thread starter Rio
  • Start date Start date
R

Rio

Hi!

I have a table with a field whose Required property is set
to Yes. The table is bound to a user input form. I want
to provide the user with an error message if the text box
on the form is null prior the updating the record.

I tried putting code in the BeforeUpdate event but that
didn’t work. I simply receive the standard MS error
message that states the field <name> can't contain a Null
value because the Required property for this field is set
to True. Enter a value in this field. (Error 3314)

How can trap for this error so I can provide the user with
a user friendly error message vs the standard MS message?
Thanks for your help.

Rio
 
I would suggest :

1.- you set Required Null property to No
2.- on the After update of you control you put the following procedure
[envent procedure]
dim strMsg as string
if (me![NameOfYourControl] & "" )="" then
strMsg ="Thank you to introduce a valid entry"
vba.msgbox (strMsg, vba.vbOkOnly, "Invalid entry")
me![NameOfYourControl].setfocus
end if

Michel
 
How can trap for this error so I can provide the user with
a user friendly error message vs the standard MS message?
Thanks for your help.

This works for me:

Private Sub OName_BeforeUpdate(Cancel As Integer)
If Len(OName & vbNullString) = 0 Then
MsgBox "You have to fill in something for OName"
Cancel = True

End If

End Sub


The BeforeUpdate event is called before the database sees the null value,
and setting the Cancel parameter prevents the update going ahead.

HTH


Tim F
 
Sorry, that is all wrong.

1. Do NOT set Required to false. If the field should always be non-null, set
Required to True. That is the point of that property. It prevents the user,
or erroneous code, from saving a record where that field is null.

2. Do NOT check in AfterUpdate. That's too late. Check in BeforeUpdate.
That's what BeforeUpdate is for.

The other respondent (TF) has it right.

TC


michel said:
I would suggest :

1.- you set Required Null property to No
2.- on the After update of you control you put the following procedure
[envent procedure]
dim strMsg as string
if (me![NameOfYourControl] & "" )="" then
strMsg ="Thank you to introduce a valid entry"
vba.msgbox (strMsg, vba.vbOkOnly, "Invalid entry")
me![NameOfYourControl].setfocus
end if

Michel

Rio said:
Hi!

I have a table with a field whose Required property is set
to Yes. The table is bound to a user input form. I want
to provide the user with an error message if the text box
on the form is null prior the updating the record.

I tried putting code in the BeforeUpdate event but that
didn’t work. I simply receive the standard MS error
message that states the field <name> can't contain a Null
value because the Required property for this field is set
to True. Enter a value in this field. (Error 3314)

How can trap for this error so I can provide the user with
a user friendly error message vs the standard MS message?
Thanks for your help.

Rio
 
Back
Top