By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,121 Members | 1,782 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,121 IT Pros & Developers. It's quick & easy.

Tips on field validation

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.