[AccessD] Error 3314 (required field) - trap in form_error

Steve Schapel miscellany at mvps.org
Fri May 25 23:15:16 CDT 2007


Gale,

Are you sure it is not recognising the control as Null?  Whereas Dan has 
suggested it may be a "" ZLS in the field, I can't see how that would 
happen, so I doubt that that's the problem.  To me, it looks like you 
are testing the wrong control.  It looks like your Screen.ActiveControl 
may not be referring to the control you think it is.  Shouldn't you have 
the ctl.SetFocus *before* identifying it as the ActiveControl?

By the way, as an aside, I think you are doing it the hard way.  Try 
this idea instead...  Set the field's Required property to No, its 
Validation Rule property to Is Not Null, and its Validation Text 
property to your user-friendly message.  Delete the code.  Voila?

-- 
Steve


Gale Perez wrote:
> Hi!
> 
> I have a form with several fields whose "Required" property is Yes, and
> I want to trap Error 3314 (required field) in the form_error.  I would like
> the code to set focus on the first field that is required and null and
> display a custom message.  The problem is that it isn't seeing the control
> as Null (so it ignores If IsNull(ctl), and just displays the customary
> message).  I would greatly appreciate any advice.
> 
> I am also interested in finding out if you can determine a control's
> table-level properties (e.g., required, and datatype) while in the form,
> instead of using an asterisk and looking at the label caption to do it.
> Here is the code:
> 
> Dim ctl as Control
> Dim strCaption as String
> ......
> If DataErr = 3314 Then
>      For Each ctl In Me.Controls
>           ' get the caption for the field label
>           strCaption = Screen.ActiveControl.Controls.Item(0).Caption
>           If Left(strCaption, 1) = "*" Then          'required field
>                If IsNull(ctl) Then  'it is ignoring this, not seeing the
> field as null
>                     ctl.SetFocus
>                     MsgBox Chr$(34) & strCaption & Chr$(34) & " is a
> required field."
>                     Response = acDataErrContinue
>                     Exit sub
>                 End If
>           End If
>      Next
> End if
> 
> Thank you so much for any assistance,
> Gale



More information about the AccessD mailing list