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

Dan Waters dwaters at usinternet.com
Sat May 26 09:26:31 CDT 2007


Steve,

I agree that while the Screen.ActiveControl may be causing the wrong control
to be checked, the value of the control for memo fields could indeed be a
zero length string and must be checked for.  In this example all controls
are being checked (I assumed all the controls on the form could contain
text), so checking for a ZLS on other controls won't hurt.

This is an example of code I use for this purpose:


Private Sub cmdDescriptionComplete()

    If DescriptionReady = False then
        Exit Sub
    End If

	...

End Sub


Private Function DescriptionReady() As Boolean

    Dim stgMessage As String

    DescriptionReady = False
        
    If IsNull(txtPONumber) Then
        stgMessage = "The PO Number field is required.@ @"
        FormattedMsgBox GstgNotReady, stgMessage, vbExclamation + vbOKOnly,
"Missing Information"
        txtPONumber.SetFocus
        Exit Function
    End If
    
    If IsNull(memProblem) Or memProblem = "" Then
        stgMessage = "The Problem field is required.@ @"
        FormattedMsgBox GstgNotReady, stgMessage, vbExclamation + vbOKOnly,
"Missing Information"
        memProblem.SetFocus
        Exit Function
    End If

    DescriptionReady = True

End Function

I like this because it give the user an informative error message and it
immediately moves the focus back to where they need to work. 

You can also set up conditional checks:  
	If Not IsNull(A) And IsNull(B) Then 
	    DescriptionReady = False
	End If

Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Steve Schapel
Sent: Friday, May 25, 2007 11:15 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Error 3314 (required field) - trap in form_error

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
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





















































































































































































More information about the AccessD mailing list