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

Access Form and Character Limit

P: 3
Microsoft Access 2003
Windows XP

I need a way to create a code for a form that if the text that is entered does not contain 7 characters, then the user will get an error message and the text field will clear.

Here is the code I have as of now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub sampleno_BeforeUpdate(cancel As Integer
  3. Private Sub sampleno_BeforeUpdate(cancel As Integer)
  5. Dim sampleno As String
  7. If Not sampleno Like "???????" Then
  9. Me.Undo
  11. MsgBox "Warning Sample Number " _
  12.         & sampleno & " was not the required length.", _
  13.         vbInformation, "InvalidInformation"
  15. End If
  17. End sub
Any help with this issue will be graetly appreciated.
Sep 14 '07 #1
Share this Question
Share on Google+
2 Replies

P: 234
Does this have to be written in code? You could create a custom input mask on the text box which uses 7 characters. Any more or any less will prompt with an error.
Sep 14 '07 #2

Scott Price
Expert 100+
P: 1,384
Explore the Len() function... It returns the length of a string, usable in vba code.

Sep 14 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.