Hi guys,
I need some help with this code snippet. I am trying to perform a validation on exit of a specific tab of my form and I am calling this function in the form exit event
Code:
Public Function fnValidateForm(Form_2 As Form) As Boolean
Dim ctl As Control
‘Dim Msg, Style, Title, Response, MyString
fnValidateForm = True
For Each ctl In Form_2.Controls
'value in the control is required
If InStr(1, ctl.Tag, "Required") > 0 Then
' no value entered or value is null
' or zero for numeric fields
If (IsNull(ctl.Value)) Or (Len(ctl.Value) = 0) Then
ctl.SetFocus
MsgBox "Please complete the highlighted control", vbCritical + vbOKOnly
Cancel = True
fnValidateForm = False
Exit For
End If
'Next
End If
Next
End Function
The problem I have is that I would like the user to remain on the tab until they fix the error, but this code block allows the user to go to the next tab without completing the errors which defeats the entire purpose of the validation.
I have been on this for quite some time, so I just need a fresh pair of eyes to tell what I need to change to get this working.
Thanks