Multiline textbox: next line undone when control is locked!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JohannKotzeVet
    New Member
    • Jul 2010
    • 5

    #1

    Multiline textbox: next line undone when control is locked!

    Good day!

    I have a form in Access that has a multiple line textbox (I called it cAbnormalities) . This text box is populated by the user ONLY through selection of options from combo boxes. I want the selected options to each be in a seperate line, and I don't want the user to be able to edit the textbox without using the combo boxes.

    Here is my code when a selection is made from the combo box:
    Code:
    Me.cAbnormalities.Locked = False
    Me.cAbnormalities.SetFocus
    Me.cAbnormalities = Me.cAbnormalities & cBoxText
    Me.cAbnormalities.SelStart = Nz(Len(Me.cAbnormalities), 1)
    SendKeys "{enter}"
    SendKeys "{backspace}"
    Me.cAbnormalities.Locked = True
    If I remove the two lines that lock and unlock the control, then my text is entered in a new line, otherwise the new line is undone! Can someone please help!

    Thanks in advance!
    Last edited by NeoPa; Jul 15 '10, 12:08 PM. Reason: Please use the [CODE] tags provided.
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    #2
    Access Help "vb constants" supplies an easy solution. Replace all your code with:
    Code:
    Me.cAbnormalities = Me.cAbnormalities & cBoxText & vbKeyReturn & vbKeyBack
    You needed to unlock the control to use SendKeys, but this is not necessary. SendKeys is not recommended unless there is no other solution, as SendKeys often gives strange results. The assignment will work even with the control locked.
    You needed to set SelStart for SendKeys, but no longer necessary.

    Welcome to Bytes!

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      All OB says is correct. I'd do it very slightly differently, but not because his wouldn't work :
      Code:
      With Me
        .cAbnormalities = .cAbnormalities & _
                          IIf(Len(.cAbnormalities) > 0, _
                              vbNewLine, "") & _
                          cBoxText
      End With
      I've split lines simply for readability, particularly with our current CODE boxes. It's still a single instruction.

      Comment

      • OldBirdman
        Contributor
        • Mar 2007
        • 675

        #4
        As usual, NeoPa, efficient & nice code. Does more than the original code does.
        My intent was to show where the old code failed, and offer a solution that did exactly what the failed code attempted. As cBoxText is a ComboBox, I assumed that there were no null or zero-length rows. If so, that should be handled elsewhere. The original post gave no indication as to what had triggered the code, nor what validity/error checking had gone before.
        As this is the first post by JohannKotzeVet, I did not know his skill level. My response was at the level of the original post.

        Comment

        • JohannKotzeVet
          New Member
          • Jul 2010
          • 5

          #5
          Still not working..

          Thanks for the replies, but it still doesn't work.

          The vbKeyReturn command only returns a "13" in the text box.

          The vbNewLine command does nothing at all.

          I have set the EnterKeyBehavio ur as "New Line In Field". I can not find a property that sets the text box to a multiple line box. But if I type within the box and press enter everything works as it should.

          Thanks for the help!

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            OB. Your response was fine and I have abvsolutely no criticism of it. I was merely offering an alternative.

            Originally posted by JohannKotzeVet
            JohannKotzeVet: The vbNewLine command does nothing at all.
            I'm a little confused as there is no separate command vbNewLine. Did you copy and paste the code exactly as displayed? The underscore (_) at the end of a line indicates that the line of code should continue onto the next line by the way. Thus lines #2 through #5 are a single statement in my posted code.

            Comment

            • JohannKotzeVet
              New Member
              • Jul 2010
              • 5

              #7
              Yes, I pasted it exactly as displayed. I then removed all the code around it to see exactly what VbNextLine does.

              Code:
               Me.cAbnormalities = Me.cAbnormalities & "Text" & vbNewLine
              The result was a single space after the text. With the next text still produced in the same line.

              How can I change that vbReturnKey does not produce an ASCII number but that it represents the actual key pressed?

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                Try :
                Code:
                Me.cAbnormalities = Me.cAbnormalities & "Text" & vbNewLine & "New Line"
                Debug.Print Me.cAbnormalities
                Then copy and paste the results here if you would.

                Comment

                • JohannKotzeVet
                  New Member
                  • Jul 2010
                  • 5

                  #9
                  Results:

                  Text
                  New line

                  Ok, so how do I fix the textbox window? Thanks! I finally feel there is hope on the horizon! :-)

                  Comment

                  • JohannKotzeVet
                    New Member
                    • Jul 2010
                    • 5

                    #10
                    Problem solved!!

                    Great!

                    I solved the problem by changing the text box's text format from 'Rich Text' back to 'Plain text'. I can live with that, it's not important for me to solve the problem with textbox still using rich text, but it would be nice how I could have solved it.. Any suggestions?

                    Thanks again! This site is great!

                    (I'm not a professional programmer so I really appreciate and need the help!)

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32669

                      #11
                      I think that's only available in Access 2007. Sorry I have no knowledge of that.

                      Comment

                      Working...