• Stopping cr/lf in text box (Access 2000 SR1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Stopping cr/lf in text box (Access 2000 SR1)

    Author
    Topic
    #401282

    I’ve struck a nasty but small problem with text boxes. Via accident one of my clients is ending up with embedded cr/lf’s in a text box. This causes all sorts of drama when printing and when exporting to txt.
    I know I could write a function to flatten the cr/lf, or add code to before update. But is there an easier way? Am I missing a ‘multi line’ True/false property that I just can’t see? Maybe there’s an input mask that will do it? (I’ve got the ‘Enter key behaivour’ as default, not new line in field) I feel like I missing something very simple.
    Thanks for your help

    Viewing 2 reply threads
    Author
    Replies
    • #789231

      If the client holds down the Ctl key and presses Enter, they will embed a carriage return in the contents of the textbox. I know of no way to prevent that except perhaps by using the keypress event to trap the Ctl+Enter combination in those fields.

    • #789503

      There is the “Enter Key Behavior” property for text controls which deals with how to handle when user just hits the Enter key rather than Tab. But as Charlotte mentioned, the Ctl+Enter is still a problem. Here is the abbreviated code I use to find this:

      If InStr(txtsomething, vbCrLf) > 0 Then
      msgbox “Invalid carriage return detected!”,vbcritical
      Cancel=True
      end if

      You can put this in your control’s BeforeUpdate event, or create a more generic function call that includes it.

      • #789718

        Thanks for your help.
        Just a note that this is a problem not just for when the user does a Ctrl-Enter. It also appears when the user pastes some info into the text box from somewhere else (for example Word), and that data has embedded Cr/Lf’s.
        One more thing to go on my wish list for Access.
        Peter

        • #789865

          Non-printing characters pasted in from another application are always a problem. If that’s the way they’re coming in, then nothing in the form is going to stop them from getting into the field, although you could use the BeforeUpdate event of the form to scrub the memo field. You would have to check for more than just vbCRLF, though, because if they’re pasting from Word, they can bring in a lot of other non-printing characters in addition to the carriage return. Here’s a snippet I’ve used for that purpose:

          If InStr(CStr(varItem), vbNewLine) > 0 Then
          varItem = Replace(CStr(varItem), vbNewLine, “, “)
          End If
          If InStr(CStr(varItem), vbCr) > 0 Then
          varItem = Replace(CStr(varItem), vbCr, “, “)
          End If
          If InStr(CStr(varItem), vbLf) > 0 Then
          varItem = Replace(CStr(varItem), vbLf, “, “)
          End If

        • #789866

          Non-printing characters pasted in from another application are always a problem. If that’s the way they’re coming in, then nothing in the form is going to stop them from getting into the field, although you could use the BeforeUpdate event of the form to scrub the memo field. You would have to check for more than just vbCRLF, though, because if they’re pasting from Word, they can bring in a lot of other non-printing characters in addition to the carriage return. Here’s a snippet I’ve used for that purpose:

          If InStr(CStr(varItem), vbNewLine) > 0 Then
          varItem = Replace(CStr(varItem), vbNewLine, “, “)
          End If
          If InStr(CStr(varItem), vbCr) > 0 Then
          varItem = Replace(CStr(varItem), vbCr, “, “)
          End If
          If InStr(CStr(varItem), vbLf) > 0 Then
          varItem = Replace(CStr(varItem), vbLf, “, “)
          End If

      • #789719

        Thanks for your help.
        Just a note that this is a problem not just for when the user does a Ctrl-Enter. It also appears when the user pastes some info into the text box from somewhere else (for example Word), and that data has embedded Cr/Lf’s.
        One more thing to go on my wish list for Access.
        Peter

    • #789504

      There is the “Enter Key Behavior” property for text controls which deals with how to handle when user just hits the Enter key rather than Tab. But as Charlotte mentioned, the Ctl+Enter is still a problem. Here is the abbreviated code I use to find this:

      If InStr(txtsomething, vbCrLf) > 0 Then
      msgbox “Invalid carriage return detected!”,vbcritical
      Cancel=True
      end if

      You can put this in your control’s BeforeUpdate event, or create a more generic function call that includes it.

    Viewing 2 reply threads
    Reply To: Stopping cr/lf in text box (Access 2000 SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: