PC Review


Reply
Thread Tools Rate Thread

Breaking up line of text > 55 chars at the last space

 
 
Silvester
Guest
Posts: n/a
 
      6th Jul 2004
I have a textbox linked to a table textfield of size 55. How can I trim a
line of text that a user enters that is greater than 55 chars and truncate
it to the last space char < 55.

Thanks for any help


 
Reply With Quote
 
 
 
 
fredg
Guest
Posts: n/a
 
      6th Jul 2004
On Tue, 6 Jul 2004 15:55:13 +0530, Silvester wrote:

> I have a textbox linked to a table textfield of size 55. How can I trim a
> line of text that a user enters that is greater than 55 chars and truncate
> it to the last space char < 55.
>
> Thanks for any help


Please always include your Access Version when posting, as this could
be done a bit differently if you have Access 2000 or newer.

The below code will work in all versions.

In the Form Control's AfterUpdate event:

If Len([ControlName]) <=55 Or IsNull([ControlName]) Then Exit Sub

Dim intX As Integer
Dim strNew As String
strNew = Left([ControlName], 55)
intX = InStr(strNew, " ")
If intX = 0 Then
[ControlName] = strNew
Exit Sub
End If

intX = Asc(Right([strNew], 1))
Do While intX <> 32
strNew = Left([strNew], Len([strNew]) - 1)
intX = Asc(Right([strNew], 1))
Loop

[ControlName] = strNew
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      6th Jul 2004
"Silvester" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)
> I have a textbox linked to a table textfield of size 55. How can I
> trim a line of text that a user enters that is greater than 55 chars
> and truncate it to the last space char < 55.


I'm not convinced this is feasible. If the field in the table has its
size set to 55 characters, the user will not be able to enter more than
55 characters in the text box, no matter what. I suppose you could use
the text box's KeyPress event to detect that the user has continued to
type in it, even after the length of its Text property is 55, but it
seems a lot like guessing to me. What if the user types 55 characters,
then accidentally types an extra letter, sees that it doesn't appear,
and is then satisfied with the all 55 characters that are currently
displayed?

I suppose you might use an unbound text box, let the user type as many
characters as he wants, and then truncate it before assigning it to the
field itself; but then you're letting the user waste time typing
characters that won't be accepted, with no clue that this is a waste of
time. That's not good user-interface design, I think.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      6th Jul 2004
"fredg" <(E-Mail Removed)> wrote in message
news:mxmf8jgugz6u.14ihxrkzdjq9g$.(E-Mail Removed)
> If Len([ControlName]) <=55 Or IsNull([ControlName]) Then Exit Sub


Ah, but Fred, if the control is bound to a text field of size 55, the
length of the control's value will *never* exceed 55.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text breaking in the middle of word not continuing on to next line =?Utf-8?B?TGl0dGxlQW5u?= Microsoft Word Document Management 3 30th Jul 2007 02:43 PM
How to read a text file populated by multi-byte chars(e.g. Chinese chars )? Peter Microsoft VB .NET 0 1st Nov 2006 02:26 PM
Breaking up line of text > 55 chars at the last space Silvester Microsoft Access Forms 3 6th Jul 2004 03:50 PM
Breaking up line of text > 55 chars at the last space Silvester Microsoft Access Form Coding 4 6th Jul 2004 03:50 PM
Inserting a non-breaking space into text on a text box Joe Microsoft Powerpoint 4 4th May 2004 05:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:10 PM.