Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sydney, Australia, New South Wales, Australia
    Posts
    251
    Thanks
    0
    Thanked 4 Times in 4 Posts

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

    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

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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.
    Charlotte

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

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

    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.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sydney, Australia, New South Wales, Australia
    Posts
    251
    Thanks
    0
    Thanked 4 Times in 4 Posts

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

    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

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •