Option Compare Database
Option Explicit
Global DeveloperMode As Boolean
Function FormEntryChk(FormName As String) As Boolean
'This function is used as a basic check for entries with null, ZLS, spaces and zeros
'Tag all form controls that need validated with tag "validate"
'Function returns "True" if check passes and "False" if one or more controls fail.
'Flagged Controls Datasheet Captions are added to a user messagebox.
On Error GoTo ErrHandler
Dim ctl As Control
Dim FlagCtl As String
FormEntryChk = True
FlagCtl = " "
For Each ctl In Forms(FormName).Controls
If ctl.Tag = "validate" Then
If Trim(ctl.Value & "") = "" Or (ctl.Value) = 0 Then
FlagCtl = FlagCtl & ctl.Properties("DatasheetCaption") & vbCrLf
FormEntryChk = False
End If
End If
Next ctl
If FormEntryChk = False Then
MsgBox ("Please complete the following fields before saving:" & vbCrLf & vbCrLf & FlagCtl), vbInformation
End If
ExitHandler:
'Add Further Code After Error Processing If Needed
Exit Function
ErrHandler:
Call ErrProcessor
FormEntryChk = False 'I don't want to save a record if there is an error.
Resume ExitHandler
End Function
Public Sub ErrProcessor()
'Developer mode = Yes results in descriptive errors and no logging
'Developer mode = No results in generic error message and error logging
If StandardFunctions.DeveloperMode = True Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Program Error"
Else
MsgBox "There was an unexpected error. Please contact your administrator.", vbExclamation, "Program Error"
'ErrorLog - capture user, form, error, error description, date and time
End If
End Sub