My Assistant
![]() ![]() |
|
|
Sep 7 2008, 10:55 AM
Post
#1
|
|
|
New Member Posts: 19 |
I want to make sure user enters only 255 characters the max allowed in Access. I use the .SelLength property of the text box. However, it always retun zero no matter how long the comment is. How can I find the real length? Please review the following code and let me know what is the correct code:
Private Sub TxtDeptComments_AfterUpdate() Dim intLength As Integer intLength = Me!TxtDeptComments.SelLength If intLength > 255 Then MsgBox ("Dept Comments cannot be longer than 255 characters. Please change your comments content.") Exit Function End If End Sub |
|
|
|
Sep 7 2008, 11:02 AM
Post
#2
|
|
|
New Member Posts: 19 |
The Exit Function should be Exit Sub. However, it still does not work!
|
|
|
|
Sep 7 2008, 11:28 AM
Post
#3
|
|
|
New Member Posts: 19 |
I have changed "intLength = Me!TxtDeptComments.SelLength" to "iintLength = len(Me!TxtDeptComments)" and it worked.
|
|
|
|
Sep 7 2008, 06:13 PM
Post
#4
|
|
|
UtterAccess VIP Posts: 13,031 From: Leicester, UK |
try
CODE Private Sub TxtDeptComments_BeforeUpdate(Cancel As Integer)
If len(Me!TxtDeptComments.text) > 255 then MsgBox ("Dept Comments cannot be longer than 255 characters. Please change your comments content.") Cancel=true else End If End Sub |
|
|
|
Sep 7 2008, 08:18 PM
Post
#5
|
|
|
Retired Moderator Posts: 19,667 |
If the TextBox is bound to a Text Field set to 255 characters, I don't think the user can enter more than 255 characters , anyway.
Have you tested the TextBox and see whether it accepts more than 255 characters (without your code)? You can test with a Field of shorter length if desired. |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 19th May 2013 - 03:29 PM |