Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

MultiLine Textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin R - 10 Mar 2008 19:49 GMT
I have a userform with a multiline textbox, the EnterKeyBehavior set to True
and MultiLine is set to True.  This form is used to create a letter and the
multiline field allows the user to enter names for a cc field on the letter.  
If more than 1 cc name is needed, the user can press the enter key while in
the multiline textbox and enter the next name until all names are entered.  
However, when the letter is generated, the names all appear on the same line
rather than starting each name on a new line.  I cannot figure this out.  
Below is the code for the cc on the userform that stores it as a variable.  
In the letter, I then use the { DOCVARIABLE "CC" } to call the value from the
userform.  Any ideas how to preserve the carriage returns entered in the
field on the user form?

       If txtCC.Value <> "" Then
           .Variables("CC").Value = txtCC.Text
       Else
           .Variables("CC").Value = " "
       End If
Jean-Guy Marcil - 10 Mar 2008 20:27 GMT
> I have a userform with a multiline textbox, the EnterKeyBehavior set to True
> and MultiLine is set to True.  This form is used to create a letter and the
[quoted text clipped - 7 lines]
> userform.  Any ideas how to preserve the carriage returns entered in the
> field on the user form?

What Word version?
In Word 2003, right now, the "Enter" character generated in a mutliline text
box is translated as Chr(13) and Chr(10). So instead of everyting on the same
line, you should get superfluous spaces (from the Chr(10)) and as many lines
as you have lines in the userform. In any case, you need code to replace the
Enter character from the userform, something like:

Dim strText As String

With Me
   If txtCC.Value <> "" Then
       strText = Replace(.txtCC.Text, Chr(13) & Chr(10), Chr(13))
       ActiveDocument.Variables("CC").Value = strText
   Else
       ActiveDocument.Variables("CC").Value = " "
   End If
End With
Kevin R - 10 Mar 2008 22:04 GMT
Still no luck.  I'm using Word 2003 SP2.  When I tried the code you
suggested, I still get the same results.  For example if I type Bill (press
Enter) and type Bob, I get:

Bill  Bob

on the same line.  The cursor will move 2 spots between the names but they
appear to be slightly larger than just your normal space.  Odd thing is if I
copy the line from the document and paste into a new blank document I get
something like:

Bill
Bob

> > I have a userform with a multiline textbox, the EnterKeyBehavior set to True
> > and MultiLine is set to True.  This form is used to create a letter and the
[quoted text clipped - 25 lines]
>     End If
> End With
Jean-Guy Marcil - 11 Mar 2008 14:21 GMT
> Still no luck.  I'm using Word 2003 SP2.  When I tried the code you
> suggested, I still get the same results.  For example if I type Bill (press
[quoted text clipped - 6 lines]
> copy the line from the document and paste into a new blank document I get
> something like:

Just to make sure we are talking about the same thing... Insert the
following two lines of code:
       MsgBox Asc(Mid(txtCC.Value, 5, 1))
       MsgBox Asc(Mid(txtCC.Value, 6, 1))
after
       If txtCC.Value <> "" Then

And test the code using your example "Bill(Enter)Bob"

See what you get.
Kevin R - 11 Mar 2008 15:55 GMT
I'll give that a try and let you know.  I think part of the problem may be
that the docvariable is inside a Word table.  If I use the docvariable
outside the table, it displays correctly.

> > Still no luck.  I'm using Word 2003 SP2.  When I tried the code you
> > suggested, I still get the same results.  For example if I type Bill (press
[quoted text clipped - 17 lines]
>
> See what you get.
Jean-Guy Marcil - 11 Mar 2008 17:40 GMT
> I'll give that a try and let you know.  I think part of the problem may be
> that the docvariable is inside a Word table.  If I use the docvariable
> outside the table, it displays correctly.

I do not know why... But in a table make sure you have a "real" ¶ at the end
of the DOCVARIABLE field. If that screws up the formatting, format that ¶ and
the following cell marker ¤ to a size of 1.
Doug Robbins - Word MVP - 12 Mar 2008 10:43 GMT
Here is another method that I have resorted to when I did not want to have a
paragraph mark after the last entry.

Dim CC As String
       If txtCC.Text <> "" Then
           strCC = txtCC.Text
           With .Bookmarks("CC").Range.Rows(1).Cells(2).Range
               If InStr(strCC, Chr(13)) = 0 Then
                   .InsertAfter strCC
               Else
                   i = 1
                   Do While InStr(strCC, Chr(13)) > 0
                       If i = 1 Then
                           .InsertAfter Left(strCC, InStr(strCC, Chr(13)) -
1)
                           strCC = Mid(strCC, InStr(strCC, Chr(13)) + 2)
                           i = 2
                       Else
                           .InsertAfter vbCr & Left(strCC, InStr(strCC,
Chr(13)) - 1)
                           strCC = Mid(strCC, InStr(strCC, Chr(13)) + 2)
                       End If
                   Loop
                   .InsertAfter vbCr & strCC
               End If
           End With
       End If

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> I'll give that a try and let you know.  I think part of the problem may be
> that the docvariable is inside a Word table.  If I use the docvariable
[quoted text clipped - 25 lines]
>>
>> See what you get.
Jean-Guy Marcil - 12 Mar 2008 14:06 GMT
> Here is another method that I have resorted to when I did not want to have a
> paragraph mark after the last entry.

But this would not work with a DOCVARIABLE field (that the poster is using),
right?
Doug Robbins - Word MVP - 12 Mar 2008 23:26 GMT
That's correct.

I came up with the method when engaged on a job to modify some templates
created by some consultants (whose name I shall not mention) in the UK who
inserted information/constructed tables in the document by setting a range
variable to the .Range of the document, then collapsing it and inserting
what they wanted then repeating the process.  For some reason, when I tried
to change the line spacing of the empty paragraph inserted after the
docvariable field, it had a detrimental effect on other parts of the
document that had been built by their code.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>> Here is another method that I have resorted to when I did not want to
>> have a
[quoted text clipped - 3 lines]
> using),
> right?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.