Bob Gajewski
rbgajewski at adelphia.net
Tue Dec 2 21:48:53 CST 2003
Darren
Two things:
1) Use the KeyPress function to test the Len after each character (incl
spaces).
2) Use the BeforeUpdate to check the Len and perform your desired action
before leaving the field, including canceling and remaining in the field if
the test fails.
Regards,
Bob Gajewski
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Darren DICK
Sent: Tuesday, December 02, 2003 22:39
To: AccessD List
Subject: [AccessD] A2K: Number of characters typed into a field.
Hello all
I need to see if the number of characters typed in to a field matches a pre
determined number...say...10.
(Data type is irrelevant. Just need to count whatever they type) Using the
Len() function I can count the
number of characters in a text box. No prob. But only after leaving the text
box
I assume 'coz Access doesn't update the contents of the control or 'accept'
the newly added contents of
a control until you leave that control.
So.. When I run the sub below in the on Change of a text box it doesn't work
'til after I leave the text box.
Does anyone know how to get it to work with each change or addition of a
character?
(I even had the code going to an unimportant control on the form to force
the update on each OnChange
then got it to return to my text box. This works fine except when I add a
space to the text I am typing the
cursor leaves the control then returns and ignores the space so I can't type
anything except 1 great big long word)
Many thanks in advance
Darren
eg
Private Sub ps_CheckExplanationLength()
Dim intCharsSoFar as integer
Dim intMinChars as integer
intMinChars = 10 ' No of characters typed before enableing apply button
intCharsSoFar = Len(Me.txtExplanation) ' Typed so far...
If intCharsSoFar > intMinChars Then
Me.cmdApply.Enabled = True ' has met the criteria
Else
Me.cmdApply.Enabled = False 'has not met
End If
End Sub
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com