Yes, correct - I am trying to make sure 5 or MORE characters are
entered. Although this explanation is a few steps above what I know
how to do. I played around and ended up putting Len([FieldName])>5
in the Expression Builder and I think it's working. I'm not sure
what BeforeUpdate or Code Builder refers to, or how you even get to
them.
Thanks for your help though - I was able to muddle through using the
Len argument. Just curious where someone would know how to build
that argument? Books? Anywhere in Microsoft Help?
missinglinq via AccessMonster.com said:
There's a couple things wrong here. First, ditnog says "I'm trying
to limit the number of characters entered in a field so that 5 or
more MUST be entered. " The code
On BeforeUpdate of the field...
If Len([YourFieldName]) > 5 Then
MsgBox "Too Long"
Cancel = True
[YourFieldName].Undo
End if
is designed to assure that 5 or LESS characters are entered, not 5
or MORE.
Next ditnog says "I tried to put that in the Expression Builder, but
it's saying "The expression you entered contains invalid syntax."
You cannot enter a sub function in the Expression Builder, it has to
go in the Code Builder! Assuming that the original post was correct,
and the intent is to assure that 5 or MORE characters are entered,
in the BeforeUpdate event of the textbox you need code like this
Private SubYourFieldName_BeforeUpdate(Cancel As Integer)
If Len(YourFieldName) < 5 Then
MsgBox ("Too short")
Cancel = True
YourFieldName.Undo
End If
End Sub
BTW, Len([YourFieldName]), Len([YourFieldName.Value]) or Len(Me.
YourFieldName.Text) would all work here. The first two are really
the same thing, as Value is the default, thus YourFieldName is the
same as YourFieldName.Value. YourFieldName.Text can only be used
when YourFieldName has the focus and so works here as well.