Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting rid of square characters on new lines 1

Status
Not open for further replies.

Luongo1

Programmer
Oct 13, 2006
52
CA
Hi,

I posted this in another forum but then thought it would be more relevant to this board. I apologize if you've seen it elsewhere.

Basically, I created a form that automatically pops up when a new document is created using a fax coversheet template in Word. It works fine, aside from the fact that on each new line in the message, a square character/symbol is inserted at the beginning of the line. Is there any way to get rid of this? It's been quite frustrating as it's really a big inconvenience to go through and delete them all once the form is submitted. I'm sure this question has been asked before but I'm a newbie and couldn't find the answer elsewhere, so any help would be appreciated...
 
Luongo1,
I would guess that you are seeing a carriage return ([tt]vbCr[/tt]) or line feed ([tt]vbLf[/tt]) character. You can replace these characters using Find and Replace or the [tt]Replace()[/tt] function in VBA.

I think the first question to ask is where are the characters coming from?[ul][li]If you view the blank template do you see the chracters?[/li][li]If not are you adding these chracters in your code?[/li][/ul]

Seeing your code might help to pinpoint the problem.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Hi CMP, thanks for your reply. I don't have the exact code available as it's on my computer at work. However, I simply used the form builder available in Word's visual basic and then told it to insert the values into the form fields in the document.

In answering your questions, no, I do not see the characters at all in the blank template, and I don't believe I am adding these to the code, although clearly I'm just a beginner so I may be without noticing.

Could you explain a bit more how to use the find and replace or replace function, and then perhaps I can use that for the time being and then try to pinpoint the problem in the code?
 
Luongo1
[ol][li]Select the non-printing character (the square) in your document and Copy it.[/li]
[li]Open the Find and Replace dialog (Edit > Replace).[/li]
[li]Paste the character into the Find What: box.[/li]
[li]Leave the Repace with: box empty.[/li]
[li]Click Replace All[/li][/ol]

This should remove all the characters with a couple simple clicks.

Hope this helps,
CMP

P.S. You might also look at recording a macro when you do the steps above. It would give you a head start on automating this process if you can't find the orginal issue.

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Is there a way to have visual basic do this automatically once the form is submitted, without the user have to take any steps? Not that I personally mind, but the template's being used by a bunch of people at work and I'd like to have things as simple as possible for them. Perhaps this replace() function you mentioned?

Thanks again for all your help CMP.
 
When you can, please post your code. As these are, it seems, coming from the displayed userform they will most likely be able to be fixed in the userform. In other words, if that symbol (and yes it is likely a acrriage return, or line feed) is placed into the formfield by the userform...then that is where it came from.
insert the values into the form fields in the document
Could you describe where the values are coming from?

Are they from a selected item in a dropddown (combobox)?
Are they from a textbox the user has entered text into?
Are they from some sort of logic in your userform?

The more information you can give, the easier it will be to come up with a fix. However, I have no doubt that if the offending characters are inserted from the userform, they can be fixed in the userform. Therefore it can be done without any user action.

Gerry
My paintings and sculpture
 
Hi Gerry, I assume they are coming from a textbox in which the user has entered information. The characters are displayed at the front of each line of the text entered in this textbox.

I will post the code as soon as I can tomorrow (Monday) morning when I have access to it...

Thanks...
 
Hi, here is the code I am using. If you see any problems which could be causing these square characters, please let me know. Thanks...

Private Sub CommandButton1_Click()
vRecipient = UserForm1.Recipient.Text
vFax = UserForm1.Fax.Text
vPhone = UserForm1.Phone.Text
vFrom = UserForm1.From.Text
vSubject = UserForm1.Subject.Text
vPages = UserForm1.Pages.Text
vMessage = UserForm1.Message.Text

ActiveDocument.FormFields("bkRecipient").Result = vRecipient
ActiveDocument.FormFields("bkFax").Result = vFax
ActiveDocument.FormFields("bkPhone").Result = vPhone
ActiveDocument.FormFields("bkFrom").Result = vFrom
ActiveDocument.FormFields("bkSubject").Result = vSubject
ActiveDocument.FormFields("bkPages").Result = vPages
ActiveDocument.FormFields("bkMessage").Result = vMessage

If UserForm1.Urgent.Value = True Then
ActiveDocument.FormFields("bkUrgent").CheckBox.Value = True
ElseIf UserForm1.Review.Value = True Then
ActiveDocument.FormFields("bkreview").CheckBox.Value = True
ElseIf UserForm1.Comment.Value = True Then
ActiveDocument.FormFields("bkcomment").CheckBox.Value = True
ElseIf UserForm1.Reply.Value = True Then
ActiveDocument.FormFields("bkreply").CheckBox.Value = True
ElseIf UserForm1.Recycle.Value = True Then
ActiveDocument.FormFields("bkrecycle").CheckBox.Value = True
End If

If UserForm1.Mail.Value = True Then
ActiveDocument.FormFields("bkMail").CheckBox.Value = True
ElseIf UserForm1.Courier.Value = True Then
ActiveDocument.FormFields("bkCourier").CheckBox.Value = True
ElseIf UserForm1.File.Value = True Then
ActiveDocument.FormFields("bkFile").CheckBox.Value = True
End If


UserForm1.Hide
End Sub
 
Just to add a couple of details to the problem... The characters appear in the document each time the user presses Enter to start a new line in the textbox (they don't appear in the form itself, just the document upon submission). Also, I've noticed that if I click the Remove Source Formatting button in Word, these characters disappear. Is there a way to apply this same function automatically upon submission of the form?

Thanks...
 
Luongo1,
That seems like the best approach but I don't know what the code is to Remove Source Formatting.

Try recording a macro to capture the action and incorporate the macro code it into your Userform?

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Thanks, I'll give that a go...

Unfortunately I can't seem to locate that particular button in Word anymore. Hopefully I can figure it out...
 
Replace characters under button's code:
vMessage=Replace(vMessage, vbCrLf, vbCr)
etc.

combo
 
Hi combo,

I tried your code but am still getting the square characters, now with no line break. I'd like to keep the line breaks but get rid of the characters if it's possible.

Thanks...
 
And this ?
vMessage = Replace(UserForm1.Message.Text, vbCrLf, vbLf)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PH - unfortunately the same result as combo's code...
 
How do you have the textbox on the userform set up?

Is MultiLine = True?

If it is, then put a label on the userform to tell the user to use Shift-Enter to make a new line in the textbox.

That may fix it.

Gerry
My paintings and sculpture
 
Hi Gerry,

I have MultiLine = true and EnterKeyBehaviour = true.

However, unfortunately using Shift-Enter produced the same result...
 
Hi Gerry, yes, I've e-mailed the file to you. Thanks...
 
Ah...I was not paying attention. The string produced in the userform is fine. It is passed to the document perfectly. The problem is....

FormFields can not, and DO NOT, take line feeds or carriage returns! You can give FormFields("Blah").Result anything you want...but it will always put that string in as linear.
Code:
Dim strIn As String
strIn = "some text, with a carriage return" & vbCrLf & _
   " and then more text, and a carriage return." & vbCrLf
ActiveDocument.FormFields("Blah").Result = strIn
will show the formfield as:

some text, with a carriage return[][]and then more text, and a carriage return[][]

With the vbCrLf showing as two little boxes - all on one line - until it hits the right margin of course.

Repeat: formfields can not, DO NOT, take multi-line text.

I am redoing your document to have the message inserted via a bookmark. However, the way you seem to want the table is causing me a bit of trouble. It needs to use explicit styles for the message content, so i am making one.

Comments:
1. use Styles! (My usual rant...)
2. use Option Explicit in your code modules
3. use explicit naming of your forms
4. use a FormField object to hold the formfield collection of the document. It makes for easier coding. Instead of:
Code:
ActiveDocument.FormFields("bkRecipient").Result = vRecipient
ActiveDocument.FormFields("bkFax").Result = vFax
ActiveDocument.FormFields("bkPhone").Result = vPhone
ActiveDocument.FormFields("bkFrom").Result = vFrom
ActiveDocument.FormFields("bkSubject").Result = vSubject
ActiveDocument.FormFields("bkPages").Result = vPages
You could do it like:
Code:
Dim DocFF As FormFields
Set DocFF = ActiveDocument.FormFields
DocFF("bkRecipient").Result = vRecipient
DocFF("bkFax").Result = vFax
DocFF("bkPhone").Result = vPhone
DocFF("bkFrom").Result = vFrom
DocFF("bkSubject").Result = vSubject
DocFF("bkPages").Result = vPages

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top