thebionicredneck
Registered User.
- Local time
- Today, 15:07
- Joined
- May 9, 2013
- Messages
- 16
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
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 me what I need to change to get this working.
Thanks
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:
[FONT=Verdana][FONT=Arial][SIZE=2]Public Function fnValidateForm(Form_2 As Form) As Boolean[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]Dim ctl As Control[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]‘Dim Msg, Style, Title, Response, MyString[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]fnValidateForm = True[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]For Each ctl In Form_2.Controls[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]'value in the control is required[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]If InStr(1, ctl.Tag, "Required") > 0 Then[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]' no value entered or value is null[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]' or zero for numeric fields[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]If (IsNull(ctl.Value)) Or (Len(ctl.Value) = 0) Then[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]ctl.SetFocus[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]MsgBox "Please complete the highlighted control", vbCritical + vbOKOnly[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]Cancel = True[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]fnValidateForm = False[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]Exit For[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]End If[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]'Next[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]End If[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]Next[/SIZE][/FONT][/FONT]
[FONT=Verdana][FONT=Arial][SIZE=2]End Function[/SIZE][/FONT][/FONT]
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 me what I need to change to get this working.
Thanks