Engineer Chris
New member
- Local time
- Today, 13:02
- Joined
- Jul 24, 2017
- Messages
- 3
This is my first post! In the code below, I am looping through the controls on a form to determine whether or not they all meet the conditions necessary to allow the data to be saved.
The code works, but I've read so many times that using the goto statement is 'bad form' so I don't want to keep it this way but I haven't come up with anything better. Please help.
By the way, there will be multiple checks eventually which is why there may seem to be an extra 'if' statement.
Thanks
The code works, but I've read so many times that using the goto statement is 'bad form' so I don't want to keep it this way but I haven't come up with anything better. Please help.
Code:
Public Function AllowSave(fForm As Form, lCriteria As Long) As Boolean
'**********************************************************************
'Input: fForm as form - Should be calling form
' lCriteria as long - Represents criteria to check. Should be a
' bitwise combination where multiple
' criteria are to be checked
'Checks for special formatting in any of the identified form's controls,
'based on the criteria specified in lCriteria. If that formatting
'exists, AllowSave returns 'False', otherwise it returns 'True'.
'**********************************************************************
'****************************************
'Error handling and variable definition
'****************************************
On Error GoTo ErrorHandler
sErrorModuleTemp = sErrorModule
sErrorModule = "AllowSave (fForm As Form): fForm = " & fForm.Name
AllowSave = False
Dim c As Control
'****************************************
'Check controls for 'unacceptable' formatting
'****************************************
For Each c In fForm.Controls
If lCriteria And ControlColor.Duplicate = ControlColor.Duplicate Then
If c.Properties("forecolor") = ControlColor.Duplicate Then
Exit Function
NotGoodProgramming:
'
End If
End If
Next
AllowSave = True
ExitFunction:
sErrorModule = sErrorModuleTemp
Exit Function
ErrorHandler:
Select Case Err.Number
Case 2455
Resume NotGoodProgramming
Case Else
If GlobalErrHandle(Err, sErrorForm, sErrorModule) Then
Resume Next
End If
End Select
Resume ExitFunction
End Function
By the way, there will be multiple checks eventually which is why there may seem to be an extra 'if' statement.
Thanks