[AccessD] Limit Text in Field

Bobby Heid bheid at appdevgrp.com
Tue Oct 31 11:45:35 CST 2006


IIRC, if you changed:
If Len(Text1.Text) > 40 Then
   MsgBox "Too many characters"
   Text1.Text = Left$(Text1.Text, 40)
End If

to:
If Len(Text1.Text) = 40 Then
   keycode=0
End If

It essentially throws away the keystroke if we are already at our maximum.

Bobby

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Tuesday, October 31, 2006 10:29 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Limit Text in Field


On 31 Oct 2006 at 8:45, Hollis, Virginia wrote:

> I tried the ' say your text field is text1, couldn't you put text1 =
> left(text1,500) & it didn't like that - it gives a runtime error about
> the BeforeUpdate can't save the record.
>
> Also, Does anyone have something that shows how many characters have
> been typed (it shows as they type)?

Create another text box Text2 to display the length and then use this:

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Text2 = Len(Text1.Text)
If Len(Text1.Text) > 40 Then
   MsgBox "Too many characters"
   Text1.Text = Left$(Text1.Text, 40)
End If-- 
Stuart


-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list