1. Set the text box's BeforeUpdate property to:
[Event Procedure]
2. Click the Build button (...) beside this.
Access opens the code window.
3. Enter:
Private Sub AccountNo_BeforeUpdate(Cancel As Integer)
If Len(Me.AccountNo) <> 10 Then
Cancel = true
MsgBox "Enter 10 digits, or press <Esc> to undo."
End If
End Sub
Setting Cancel to True stops the user from exiting the box.
BTW, if you need to store some accounts with leading zeros, AccountNo must
be a Text field (not a Number field) in your table.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Pres Holod" <ho***@optonline.net> wrote in message
news:40**********************@news.newsgroups.ws.. .
When entering an account number I ant a message to appear if the account
number is not 10 digits. I have figured out how to get the message in a
macro BUT I dont want the user to be able to proceed to another field
until the account number is fixed. What do I have to add to the code?
Len([AccountNo])<>10
Preston Holod