Re: Remove special formatting characters from textbox contents

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Peter Hewett (nospam_at_xtra.co.nz)
Date: 09/02/04


Date: Fri, 03 Sep 2004 03:41:16 +1200

Hi Katherine

What I'd do is cut 'n paste specific character from the Word document into your TextBox
controls to isolate *exactly* what's causing the problem. If you're using Word 2000 or
later you can then use the Replace function to strip out the junk characters in the
Controls AfterUpdate event. You could do it in the controls Change event handler but that
event is triggered *every* time you add/delete/change a character in the control.

I'd strip out these characters which Word uses; Chr$(10) (or vbLf) for new line
(Shift+Enter ), Chr$(12) (or vbFormFeed) for section breaks (all types) and Chr$(13) (or
vbCr) for paragraph marks (Enter).

Private Sub txtA_AfterUpdate()
    Dim strText As String

    ' Strip Newline, Paragraph mark and section breaks
    strText = Replace(txtA.Text, vbLf, vbNullString)
    strText = Replace(strText, vbCr, vbNullString)
    txtA.Text = Replace(strText, vbFormFeed, vbNullString)
End Sub

The above assumes your TextBox control is named "txtA". Also, I've just completely
deleted the character rather than replace it with another. This obviously will impact the
format of the text (as you want) but you may need to do something else if the final format
is not correct.

HTH + Cheers - Peter

Katherine <Katherine@discussions.microsoft.com>, said:

>Where users are cutting and pasting text into my userform textboxes, they are
>picking up paragraph marks etc. This is causing a runtime error when these
>details arte submitted into the custom document property fields in the word
>document. Cutting and pasting into the textbox from notepad doesn't produce
>an error, so we're pretty sure it's the formatting that's causing the
>problem.
>
>What I need to do is strip out all the paragraph marks etc from the textbox
>contents before they are submitted into the document. I figure I need some
>kind of if statement, but the actual syntax is beyond me - I have no idea
>where to begin.
>
>a - z, 1 - 0, full stops (periods) and spaces are all valid entries. How do
>I get rid of the other gumpf?



Relevant Pages

  • Referencing a Subprocedures Name
    ... The trick is to iterate through all the controls, ... Sub PastReply ... checkboxes to the collection that hosts the classes. ... >which is textbox specific I can simply reference the ...
    (microsoft.public.excel.programming)
  • Re: how to get both old and new value for a changed text box
    ... If IsDirty Then ... Just curious...How big is this Access database? ... I was just noticing if I leave a textbox, ... I usually read data directly into controls like textbox's using a data ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Custom Menu
    ... the column captions will take their names from the textbox controls. ... Can you cycle thru the fields collection and set the each txtbox to the ... When you set the control source for each textbox, set the name of the text ...
    (microsoft.public.access.modulesdaovba)
  • Re: how to add several HTML elements to the web page dynamically using
    ... Protected Sub Button1_Click ... Dim Textbox1 As New TextBox ... is there a way to read the state of de website which controls should be "active" ... The controls, I supoose can be added via the contenttemplate of the update panel, but what about the script can it be added to the page at runtime? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Looking for general Validating and Validated events in VS2005
    ... If typeof C Is Textbox ... Iterating through controls will happen at run time. ... When I use the wizard to build controls in the form, ... my extended textbox doesn't get created by those wonderful form ...
    (microsoft.public.dotnet.general)