Text box with character turns....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kcdoell
    New Member
    • Dec 2007
    • 230

    Text box with character turns....

    Hello:

    I have a continous form where I have a field called notes. It is text and I have a 255 chrc limit on it. I am limited to how wide this field can be. I do not want it to be a memo field but I would like to have my text box act and behave like one. That is that it will auto character turn the sentences and then a small scroll box would appear on the box for viewing purposes. Can that be done???

    Thanks,

    Keith.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi Keith. If you resize the notes text box vertically to be two or three lines in length instead of the single line default you will find that text will wrap automatically. To have scroll bars shown for your users change the Scroll Bars property of the text box from None to Vertical.

    -Stewart

    Comment

    • kcdoell
      New Member
      • Dec 2007
      • 230

      #3
      Stewart:

      Thanks for the reply. That did what I wanted it to do. I did have the settings as you suggested but found out that I need to have a minimum height on the text box to kick in the wrapping feature. In my case with Ariel 8 font the height had to be set to 0.24.

      Since I set the character limitation to 255, is there a way to give the user a message box to tell them they have reached the limitation. Currently, Access just beeps.

      Thanks,

      Keith.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by kcdoell
        Stewart:

        Thanks for the reply. That did what I wanted it to do. I did have the settings as you suggested but found out that I need to have a minimum height on the text box to kick in the wrapping feature. In my case with Ariel 8 font the height had to be set to 0.24.

        Since I set the character limitation to 255, is there a way to give the user a message box to tell them they have reached the limitation. Currently, Access just beeps.

        Thanks,

        Keith.
        1. Let's assume your Text Box name is txtCharLength.
        2. Declare the following Constant in your Form's General declarations Section:
          [CODE=vb]Const MAXIMUM_NUM_OF_ CHARACTERS As Integer = 255[/CODE]
        3. Copy and Paste the following code in the KeyPress() Event of txtCharLength:
          [CODE=vb]Private Sub txtCharLength_K eyPress(KeyAsci i As Integer)
          Dim txt As TextBox
          Set txt = Me!txtCharLengt h

          If Len(txt.Text) - txt.SelLength >= MAXIMUM_NUM_OF_ CHARACTERS Then
          'Let's allow the Backspace Key
          If KeyAscii <> vbKeyBack Then
          KeyAscii = 0 'Negate the Keystroke
          MsgBox "You have reached the Maximum Number of Characters for this Text Box"
          End If
          End If
          End Sub[/CODE]
        4. Copy and Paste the following code in the Change() Event of txtCharLength:
          [CODE=vb]Private Sub txtCharLength_C hange()
          Dim txt As TextBox
          Dim Msg As String

          'You must allow for the possibility that Text may be Copied and Pasted into
          'this Text Box, ion which case the KeyPress() Event will never be fired

          Msg = "You Text exceeds the Maximum Number of Characters allowed (255) for this " & _
          "Text Box. The Text has been truncated to " & MAXIMUM_NUM_OF_ CHARACTERS & _
          " characters."

          Set txt = Me!txtCharLengt h

          If Len(txt.Text) > MAXIMUM_NUM_OF_ CHARACTERS Then
          MsgBox Msg
          txt.Text = Left$(txt.Text, MAXIMUM_NUM_OF_ CHARACTERS) 'truncate to Max
          'Move the Cursor to the end of the Text Box
          txt.SelStart = MAXIMUM_NUM_OF_ CHARACTERS
          End If
          End Sub[/CODE]
        5. You should now be covered from every angle, any questions please feel free to ask.

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          This method gives the user a running count of how many characters they have left to type, then pops a warning box when they reach the limit.

          Place a label above or next to the textbox.
          Make the label's caption "255 Characters Left"
          Place this code behind the textbox:

          Code:
          Private Sub YourTextBox_Change()
            CharacterCountLabel.Caption = 255 - Len(Me.YourTextBox.Text) & " Characters Left"
            If Len(Me.YourTextBox.Text) = 255 Then
          	MsgBox "No more characters allowed!"
            End If
          End Sub
          Linq ;0)>

          Comment

          • kcdoell
            New Member
            • Dec 2007
            • 230

            #6
            [QUOTE=ADezii][list=1][*] Let's assume your Text Box name is txtCharLength.[*] Declare the following Constant in your Form's General declarations Section:
            [CODE=vb]Const MAXIMUM_NUM_OF_ CHARACTERS As Integer = 255[/CODE][*] Copy and Paste ............... ........

            ADezii:

            I never needed to declare a constant in an object's general declarations section yet. How would I do that?

            Thanks,

            Keith.

            Comment

            • kcdoell
              New Member
              • Dec 2007
              • 230

              #7
              Originally posted by kcdoell

              ADezii:

              I never needed to declare a constant in an object's general declarations section yet. How would I do that?

              Thanks,

              Keith.
              I think I just found it in the VB window. I did the following:

              [code=vb]
              Option Compare Database
              Const MAXIMUM_NUM_OF_ CHARACTERS As Integer = 255
              [/code]

              "Option Compare Database" was there as a default so I left it. Was that the correct way to input that?

              Thanks for your help.

              Keith.

              Comment

              • kcdoell
                New Member
                • Dec 2007
                • 230

                #8
                Hello I just applyed the ideas and came up with this end result:

                [code=vb]
                Option Compare Database
                Const MAXIMUM_NUM_OF_ CHARACTERS As Integer = 255

                Private Sub Comment_Change( )

                'Counts the amount of characters that remain to write in the comments text box
                LblCharCount.Ca ption = 255 - Len(Me.Comment. Text) & " Characters Left"
                If Len(Me.Comment. Text) = 255 Then
                End If
                End Sub

                Private Sub Comment_KeyPres s(KeyAscii As Integer)

                'Will warn the user when they have reached the maximum character length
                Dim txt As TextBox
                Set txt = Me!Comment

                If Len(txt.Text) - txt.SelLength >= MAXIMUM_NUM_OF_ CHARACTERS Then

                'Let's allow the Backspace Key
                If KeyAscii <> vbKeyBack Then
                KeyAscii = 0 'Negate the Keystroke
                MsgBox "You have reached the Maximum Number of" & _
                " Characters for the Comment section which is 255. Please refrase" & _
                " your comments to shorten the length.", 64, "Max Characters Reached!"

                'Move the Cursor to the end of the Text Box
                txt.SelStart = MAXIMUM_NUM_OF_ CHARACTERS

                End If
                End If
                End Sub
                [/code]

                I like the count down feature, cool stuff!

                Thanks a lot to both of you!!

                Keith :-)

                Comment

                Working...