-
I am new to VB and would like to know what is the best method for Validating fields. Am I better off Validating at Save time eg. When the user has finished creating a Team Member record and goes to save it, does the Team exist in the Team Table for that record, does the club exist in the Club table for that record etc. Or would it be easier for the user to get told at entry time that their input is not correct? If anybody has any ideas I would appreciate an example.
Thanx in advance, Thomas
-
I don't know what method you use to for editing control but here's what I found works well. First I always validate at data entry time. That way there still thinking about that particuallar field and they will not be able to sneak garbage data past. Second I use maskedboxs in an array for data entry. (You can also do this with regular text boxes) You can then set up a varily simple validation routine like the following:
Private Sub MaskEdBox1_Validate(Index As Integer, Cancel As Boolean)
Select Case Index
Case 2
If MaskEdBox1(Index).text <> ?? Then
Cancel = True
x = MsgBox("some message", vbOKOnly)
MaskEdBox1(Index).SetFocus
Else
Do something with data if required
End If
Case 4
By doing it this way they are forced to stay in that field until they get it right or cancel data entry.
Hope this helps.
DonB
-
If you are working against a remote database, it is better from a performance stand point to validate all at once.
From a user standpoint it is better to validate field by field. One thing you might want to consider for field by field validation, is to not clang the user with a message box every time the data doesn't validate... instead, change the text color to Red and allow them to continue. When they actually execute the Save, you can check for Red text, and then give them the message box. This is especially good in applications where a lot of data entry is going on... the user can see they made an error and address it immediately or when they get done with the other fields in the row.
Bash
-
Thank you both for that excellent advice. It is exactly what I was looking for.
Cheers, Thomas