UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Visually Validate Your Forms With A Class, Any Version    
 
   
JonSmith
post Nov 28 2013, 05:44 AM
Post#1



Posts: 3,158
Joined: 19-October 10



Inspired by a topic by Nuclear_Nick to have a more elegant solution to the default message when a user misses a required field I have created a set of classes that can be used to validate your data entry forms.
This class will highlight all validation errors on the form at once rather than only one at a time and is a very visual solution to your users.
I've attached a screenshot that will explain it best.
The code is nearly all contained within 2 class modules and all you need to put on your form is
CODE
Dim clsForm As clsFormValidationEvents
Private Sub Form_Load()
    Set clsForm = New clsFormValidationEvents
    clsForm.Init Me.Form, 2, 2366701
End Sub

This should hopefully make the code very flexible and portable (as originally requested by Nuclear_Nick)
In order to highlight a control as one that needs to be validated you either need to have the Required property in the underlying table set to true or for unbound fields you can set the controls validation rule to "Is not null". I haven't built in any more complex validation checks at this point but I may in the future.
Attached File(s)
Attached File  ScreenShot.jpg ( 172.16K )Number of downloads: 315
Attached File  Validation.zip ( 77.19K )Number of downloads: 419
 
Go to the top of the page
 
nmurray
post Dec 1 2014, 04:03 AM
Post#2



Posts: 439
Joined: 28-February 11
From: UK


Like this a lot. However, if the user presses ESC to cancel editing, the validation stays on when navigating the other records. This fixes this.

CODE
Private Sub frmObject_Current()
Dim ctl As control
    'Loop through the collection of controls and remove existing validation.
    'This makes sure that the original back colour isn't set to the err colour
    'If editing the record has been cancelled
    If Not frmObject.Dirty Then
        For Each ctlVali In ValidationControls
            ctlVali.ClearValidation
        Next
    End If
End Sub

Public Function Init(frm As Form, HighlightType As Integer, ErrCol As Long)
    'Set the values for various properties and capture the before update event.
    iHighlightType = HighlightType
    lngErrCol = ErrCol
    Set frmObject = frm
    frmObject.BeforeUpdate = "[Event Procedure]"
    frmObject.Oncurrent = "[Event Procedure]" ' Checks for record movement with Validation left uncleared
    Set ValidationControls = New Collection 'Set here so that it doesn't err on ValidateForm()
End Function
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    12th December 2017 - 06:59 AM