B
BruceM
I have the following code as part of validatation in a form's Before Update
event:
Dim ctl As Control, blnNoVal as Boolean
For Each ctl In Me.Controls
If IsNull(ctl) And ctl.Tag = "R" Then
blnNoVal = True
Else
blnNoVal = False
End If
Next ctl
If blnNoVal = True Then
Exit Sub
Else
' perform validation
End If
Five controls in one section of the form have "R" as the tag. If these
controls are also null, it means that the section of the form was not
started, which is OK. In that case the rest of the validation code is
skipped (Exit Sub). However, if any of the five has a value, they all need
a value. My idea was that if blnNoVal evaluates to False, validation needs
to occur. As the code stands, if the first four controls have a value but
the fifth does not, at the end of the loop blnNoVal will be True, and
validation will not run, but validation needs to run in order to inform the
user that the fifth control needs a value. I have been looking for a way to
step out of the loop and go on to the next section of code as soon as
blnNoVal evaluates to False. I don't know if this is a reasonable approach
in the first place, but it seems rather tidy except for the stated question.
event:
Dim ctl As Control, blnNoVal as Boolean
For Each ctl In Me.Controls
If IsNull(ctl) And ctl.Tag = "R" Then
blnNoVal = True
Else
blnNoVal = False
End If
Next ctl
If blnNoVal = True Then
Exit Sub
Else
' perform validation
End If
Five controls in one section of the form have "R" as the tag. If these
controls are also null, it means that the section of the form was not
started, which is OK. In that case the rest of the validation code is
skipped (Exit Sub). However, if any of the five has a value, they all need
a value. My idea was that if blnNoVal evaluates to False, validation needs
to occur. As the code stands, if the first four controls have a value but
the fifth does not, at the end of the loop blnNoVal will be True, and
validation will not run, but validation needs to run in order to inform the
user that the fifth control needs a value. I have been looking for a way to
step out of the loop and go on to the next section of code as soon as
blnNoVal evaluates to False. I don't know if this is a reasonable approach
in the first place, but it seems rather tidy except for the stated question.