Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Insert vbCr every 10 characters

Posted on 2003-03-18
9
Medium Priority
?
478 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
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
Independent Software Vendors: 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

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.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

578 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