?
Solved

Insert vbCr every 10 characters

Posted on 2003-03-18
9
Medium Priority
?
475 Views
Last Modified: 2012-06-27
How can I insert a vbCr every 10 characters in real time (as the user is typing in a form)?

Example:
Hello, my name is Bob
=
Hello, my
name is Bo
b

But I only want it to insert the vbCr if the user hasn't entered a new line.  So I want it to have a vbCr at least every 10 characters.

Example:
Hello,<user-entered break>
my name is Bob.
=
Hello,
my name is
 Bob.

Thanks!
0
Comment
Question by:Alopederii
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Author Comment

by:Alopederii
ID: 8159885
One additional requirement -- it needs to work even if the user is modifying what has been typed earlier.  So if they are deleting characters, the position of the non-user-entered vbCrs should be moved accordingly.
0
 
LVL 3

Accepted Solution

by:
wide_awake earned 1000 total points
ID: 8160815
Here's some code to get you started:


Dim charCount As Integer

Private Sub Text0_GotFocus()
    charCount = 0
End Sub

Private Sub Text0_KeyPress(KeyAscii As Integer)
Text2 = Text2 & " " & KeyAscii

    If charCount >= 10 Then
        SendKeys (vbCrLf)
        charCount = 0
    End If
   
    Select Case KeyAscii
    Case 8
        If charCount > 0 Then
            charCount = charCount - 1
        End If
    Case 13
        charCount = 0
    Case Else
        charCount = charCount + 1
    End Select
   
End Sub

That'll work, the only thing you have to do is change the "GotFocus" subroutine to figure out what charCount should be if your text field is not initially empty.

Oh, one other thing: make sure you set the "enter key behaviour" to "new line in field" instead of "default"

-Mark.
0
 
LVL 28

Expert Comment

by:TextReport
ID: 8161093
I would do this in the AfterUpdate Event of the control they are entering. However, I suspect you may want to check for CR and LF in chich case you can use vbCrLf rather than vbCr

Cheers, Andrew

dim strTEXT as string
dim strOld as string

    strOLD = Replace(me.txtMyControl, vbCr, "")
    for cnt = 1 to len(strOLD)
        strTEXT = strTEXT & Mid(strOLD,cnt)
        if cnt mod 10 = 0 then
           strTEXT = strTEXT & vbCR
        end if
    Next cnt

    Me.txtMyControl = strTEXT
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:Alopederii
ID: 8161894
Thank you both for your input.  I created code on AfterUpdate to format it then.

One final step and then I'll award the points:
How can I make a text box have vertical AND horizontal scroll bars?
0
 
LVL 5

Author Comment

by:Alopederii
ID: 8162071
Actually, I am going to split the points.  You both helped to point me in the right direction.

I am going to post a separate question about the scrollbars.  Feel free to answer that one as well. ;)
0
 
LVL 28

Expert Comment

by:TextReport
ID: 8162136
The textbox has a ScrollBars property that you can set to Neither, Both, horizontal or verticle.

Cheers, Andrew
0
 
LVL 5

Author Comment

by:Alopederii
ID: 8162169
Am I looking in the wrong place?  When I go to Properties > Format the Scroll Bars proerty only shows None or Vertical.  I am using Access 2002.
0
 
LVL 28

Expert Comment

by:TextReport
ID: 8162212
I have commented on your other question, the Scrollbar is only None or Vertical in teh standard text box but if you insert the Microsoft Forms 2 Textbox all 4 options are available. You insert this as an ActiveX control.

Cheers, Andrew
0
 

Expert Comment

by:Banath
ID: 8162809
Per request - points reduced for split.

Alopederii- please accept a comment by wide_awake as the answer.

TextReport- please collect your points in:
http://www.experts-exchange.com/Databases/MS_Access/Q_20555415.html

Banath
EE Moderator
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question