A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

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



 
 
Thread Tools Display Modes
  #1  
Old July 6th, 2004, 11:25 AM
Silvester
external usenet poster
 
Posts: n/a
Default Breaking up line of text > 55 chars at the last space

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


  #2  
Old July 6th, 2004, 03:21 PM
fredg
external usenet poster
 
Posts: n/a
Default Breaking up line of text > 55 chars at the last space

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.
  #3  
Old July 6th, 2004, 03:44 PM
Dirk Goldgar
external usenet poster
 
Posts: n/a
Default Breaking up line of text > 55 chars at the last space

"Silvester" wrote in message

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)


  #4  
Old July 6th, 2004, 03:50 PM
Dirk Goldgar
external usenet poster
 
Posts: n/a
Default Breaking up line of text > 55 chars at the last space

"fredg" wrote in message

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)


 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2000 export to Tab deliminated text file - how to control tabs at end of line BeamGuy General Discussions 1 June 4th, 2004 02:17 PM
Too many hyperlinks? [email protected] Powerpoint 7 May 25th, 2004 02:19 AM
Edit same text in multiple locations angelo11 Formatting Long Documents 2 May 19th, 2004 06:24 PM
Vertical Text Orientation Paul Anderson [MSFT] Visio 0 May 11th, 2004 05:16 PM
Text boxes-help Jon Peltier Charts and Charting 0 January 26th, 2004 05:46 PM


All times are GMT +1. The time now is 12:06 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.