UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Checking text length in Comment box    
 
   
ysb234
post 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
Go to the top of the page
 
+
ysb234
post 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!
Go to the top of the page
 
+
ysb234
post 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.
Go to the top of the page
 
+
dannyseager
post 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
Go to the top of the page
 
+
vtd
post 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 the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th May 2013 - 03:29 PM