469,627 Members | 1,104 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

Tips on field validation

I am trying to validate the fields in my database.I have already
validated the fields to check for not null.Here is what I have written
for Numeric and text field.
Private Function EENUM()
On Error GoTo EENUMErr

If IsNull(Me.EmployeesID) Or Me.EmployeesID = "" Or Me.EmployeesID
< 0 Then
MsgBox "Employee Number Cannot Be Left Blank", vbOKOnly,
"Employee Number"
EmployeesID.SetFocus
End If

EENUMErr:
If Err <> 0 Then
MsgBox "Error #: " & Err.Number & " Description: " &
Err.Description, , "Employee ID Error!"
Exit Function
End If

End Function (This checks for nulls values in the employee number
field)

I want to add a message if a text field is entered in this field And I
want to put up a message if the user enters more than 4 digits.I have
already set the field length to 4 at the design time

And I have written the following for the text field.
Private Function EFN()
On Error GoTo EFNErr

If IsNull(Me.FirstName) Or Me.FirstName = "" Then
MsgBox "Enter Employees First Name", vbOKOnly, "First Name"
FirstName.SetFocus
End If

EFNErr:
MsgBox "Error #: " & Err.Number & " Description " & Err.Description, ,
"First Name Error!"
Exit Function
End Function

This checks for nulls in the Employye field and I want to add a
message if user enters anything other than text.

Can anyone help me with this?

Thanks
Nov 12 '05 #1
2 10129
See MSKB 208949 for an example of field validation:
Flexible Input Mask for Entering Five- or Nine-Digit ZIP Codes
http://support.microsoft.com/default...b;en-us;208949

You can set a validation rule property for the allowed length, as shown in step 3 of the
above article. As an alternative, you can set this validation rule at the field level in
table design view, and include the appropriate validation text if the data entry does not
follow this rule.

Some other useful articles include MSKB 210385:
Validation Rule to Accept Only Alphabetical Characters
http://support.microsoft.com/default...b;en-us;210385

and MSKB 209049
Input Mask Character (!) Does Not Work as Expected
http://support.microsoft.com/default...b;en-us;209049

For example, a validation rule of Like "####" should limit the data entry to (4)
numeric digits.

Tom
____________________________________________

"Doslil" <do****@hotmail.com> wrote in message
news:c6*************************@posting.google.co m...

I am trying to validate the fields in my database.I have already
validated the fields to check for not null.Here is what I have written
for Numeric and text field.
Private Function EENUM()
On Error GoTo EENUMErr

If IsNull(Me.EmployeesID) Or Me.EmployeesID = "" Or Me.EmployeesID
< 0 Then
MsgBox "Employee Number Cannot Be Left Blank", vbOKOnly,
"Employee Number"
EmployeesID.SetFocus
End If

EENUMErr:
If Err <> 0 Then
MsgBox "Error #: " & Err.Number & " Description: " &
Err.Description, , "Employee ID Error!"
Exit Function
End If

End Function (This checks for nulls values in the employee number
field)

I want to add a message if a text field is entered in this field And I
want to put up a message if the user enters more than 4 digits.I have
already set the field length to 4 at the design time

And I have written the following for the text field.
Private Function EFN()
On Error GoTo EFNErr

If IsNull(Me.FirstName) Or Me.FirstName = "" Then
MsgBox "Enter Employees First Name", vbOKOnly, "First Name"
FirstName.SetFocus
End If

EFNErr:
MsgBox "Error #: " & Err.Number & " Description " & Err.Description, ,
"First Name Error!"
Exit Function
End Function

This checks for nulls in the Employye field and I want to add a
message if user enters anything other than text.

Can anyone help me with this?

Thanks
Nov 12 '05 #2
TC
I said to you in an earlier thread:

You should put checking code like this in the BeforeUpdate event - not in a
private function.. If an error occurs, set the Cancel parameter of that
event to True. That will stop the focus from leaving the control. Discard
the SetFocus statement.

But you are naturally free to ignore that advice! :-)

TC
"Doslil" <do****@hotmail.com> wrote in message
news:c6*************************@posting.google.co m...
I am trying to validate the fields in my database.I have already
validated the fields to check for not null.Here is what I have written
for Numeric and text field.
Private Function EENUM()
On Error GoTo EENUMErr

If IsNull(Me.EmployeesID) Or Me.EmployeesID = "" Or Me.EmployeesID
< 0 Then
MsgBox "Employee Number Cannot Be Left Blank", vbOKOnly,
"Employee Number"
EmployeesID.SetFocus
End If

EENUMErr:
If Err <> 0 Then
MsgBox "Error #: " & Err.Number & " Description: " &
Err.Description, , "Employee ID Error!"
Exit Function
End If

End Function (This checks for nulls values in the employee number
field)

I want to add a message if a text field is entered in this field And I
want to put up a message if the user enters more than 4 digits.I have
already set the field length to 4 at the design time

And I have written the following for the text field.
Private Function EFN()
On Error GoTo EFNErr

If IsNull(Me.FirstName) Or Me.FirstName = "" Then
MsgBox "Enter Employees First Name", vbOKOnly, "First Name"
FirstName.SetFocus
End If

EFNErr:
MsgBox "Error #: " & Err.Number & " Description " & Err.Description, ,
"First Name Error!"
Exit Function
End Function

This checks for nulls in the Employye field and I want to add a
message if user enters anything other than text.

Can anyone help me with this?

Thanks

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Shabam | last post: by
3 posts views Thread by Kivak Wolf | last post: by
1 post views Thread by Niclas | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.