UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> Required Controls    

clsRequiredControls is designed to identify missing data before a form saves a record. It uses a collection that you populate with the controls that must have data.

CODE
Option Compare Database
Option Explicit

' Module: clsRequiredControls
' DateTime: 11/21/2013 10:43:52 AM
'
' Description:
'   manage required controls on a form

'---------------------------------------------------------------------------------------
   
Private Const cstrModule As String = "clsRequiredControls"
Private mcolControls As Collection
Public Property Get Controls() As Collection
' Procedure: Controls
' DateTime: 11/21/2013 10:43:52 AM
'
' Description: collection of controls being managed
'--
   On Error GoTo HandleExit
   
   
   Set Controls = mcolControls
HandleExit:
End Property
Public Property Set Controls(rData As Collection)
' Procedure: Controls
' DateTime: 11/21/2013 10:43:52 AM
'
' Description: collection of controls being managed
'--
   On Error GoTo HandleExit
   
   
   Set mcolControls = rData
HandleExit:
End Property
Public Function FindEmptyControl() As Variant
' Procedure: FindEmptyControl
' DateTime: 11/21/2013 10:43:52 AM
'
' Description: finds the first required control that is null
'--

   Const cstrProcedure = "FindEmptyControl"

   Dim ctrl As Control
10    On Error GoTo HandleError

   'enumerate the collection
20    For Each ctrl In Controls

30      If IsNull(ctrl) Then
       'identify null control and quit enumeration
           
40          Set FindEmptyControl = ctrl
50          Exit For
60      Else
       'indicate no null controls
70          FindEmptyControl = 0
80      End If
90    Next


HandleExit:

100   Exit Function

HandleError:
110   ErrorHandle Err, Erl(), cstrModule & "." & cstrProcedure
120   Resume HandleExit
End Function

Public Function FindEmptyControls() As Integer
' Procedure: FindEmptyControls
' DateTime: 11/21/2013 10:43:52 AM
'
' Description: counts empty controls
'--
   
   Const cstrProcedure = "FindEmptyControls"
   
   Dim ctrl As Control
   Dim cntr As Integer
   On Error GoTo HandleError

   For Each ctrl In Controls
       If IsNull(ctrl) Then
           cntr = cntr + 1
       End If
    Next

   FindEmptyControls = cntr
   
HandleExit:
   
   Exit Function

HandleError:
   ErrorHandle Err, Erl(), cstrModule & "." & cstrProcedure
   Resume HandleExit
End Function

Sample Usage:

CODE
10  Set reqCtrls = New clsRequiredControls

20  With reqCtrls
       'if controls collection has been populated at the form level
30      Set .Controls = Me.RequiredControls

40      If IsNumeric(.FindEmptyControl) Then
           'method has returned a 0 to indicate no null required controls
100         Debug.Print "No empty controls"

50      Else
60          If IsObject(.FindEmptyControl) Then
               'method has returned a required control that needs content
70              Set ctrl = .FindEmptyControl
80              Debug.Print ctrl.Name
90          End If

110     End If

Creative Commons License
Required Controls by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 2,369 times.  This page was last modified 10:04, 22 November 2013 by Glenn Lloyd.   Disclaimers