Validating

  • Thread starter Thread starter Alex Martinez
  • Start date Start date
A

Alex Martinez

Hello,

I am not sure if this is called validating, but what I want to do is enter a
policy number that has 10 digits (example - A123456789) if the user inputs 9
digits I want Access to produce an error message that states it needs 10
digits. Nothing fancy. Any help will be appreciated. Thank you.
 
You could use the BeforeUpdate event of the text box where this entry is
made to ensure that the length is 10 characters:

Private Sub Text0_BeforeUpdate(Cancel As Integer)
If Len(Me.Text0) <> 10 Then
Cancel = True
MsgBox "Enter 10 characters, or press <Esc> to undo."
End If
End Sub
 
Alex said:
if the user inputs 9
digits I want Access to produce an error message that states it needs 10
digits. Nothing fancy.

CurrentProject.Connection.Execute _
"ALTER TABLE MyTableName ADD CONSTRAINT needs_ten_digits" & _
" CHECK ( LEN(my_column_name) = 10)"
 
Back
Top