Set the ValidationRule property on the field to
Is Null Or Like "????????"
Pergunta
I have a field on an MS Access form that has the following validation rule:
Is Null Or Between 10000000 And 99999999
This basically restricts to the user to be able to enter 8 digits only.
Is there a way to change the validation rule so that the user can enter 8 alpha numeric characters?
Solução
Set the ValidationRule property on the field to
Is Null Or Like "????????"
Outras dicas
One way to enforce this within the user interface would be via an input mask instead of validation:
AAAAAAAA
Update: As @Chris Rolliston points out, you are better off using validation at the database level to ensure you maintain valid data. How you do that will vary depending on the db engine (MS Access, SQL Server, Oracle, MySQL, PostgreSQL, etc.) where the table physically resides.
You can put VBA in the AfterUpdate event of the object like:
If len(Trim(Me.MyTextField)) <> 8 then
Msgbox "Please enter an 8-digit key"
Me.MyTextField = ""
End If
Make sure the Trim function is in there to eliminate the user trying to add empty spaces.