Text Formfields?

J

jille

Hi,

I've created a userform with a textbox that allows the user to enter
multiple lines of text and use the Enter key to add additional paragraphs.

I'm trying to move this text to a text formfield but it's pulling out the
hard carriage returns. I know that if the user was filling out the formfield
directly, they would be able to use the Enter key within the field.

I've already tested the code to ensure that it works, for example, when I
use a simple bookmark (instead of the formfield) and it does. The obvious
solution is to use a bookmark but this option isn't viable due to other
issues.

Any suggestions on getting the text formfield to recognize the hard carriage
return?

Really desperate for an answer so any thoughts would be most appreciated.

Thanks,
Jille
 
J

Jay Freedman

I have some questions about what you've done and what you're seeing,
because your description doesn't match my experience.

- Is the textbox in the userform set to MultiLine = True and
EnterKeyBehavior = True?

- Is the code in your userform something like this?

ActiveDocument.FormFields("Text1").Result = TextBox1.Text

- Do you really see a single long line in the form field where you
expect to see several lines?

When I set up a userform as I indicated in the first two items, the
form field shows multiple lines, but each line starts with a square.
That's because the return in the userform's textbox consists of two
characters, Chr(13) & Chr(10), while a return in the form field is
only the Chr(13). The Chr(10) appears as the box. The solution for
that is to write the line of code as

ActiveDocument.FormFields("Text1").Result = _
Replace(TextBox1.Text, Chr(10), "")

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
J

jille

Hi Jay,

Yes to all questions and I did get the squares instead of hard carriage
return but I didn't know what it meant.

You identified the exact problem...

Thanks for your help,

Jille
 
J

jille

I should clarify....

I am getting two small boxes where a single hard carriage should appear.
When I try the code you suggest I get one box instead of two. So I replaced
both the Chr(10) & 13 and determined that they were both being represented as
a small box. Now how do I add a hard carriage in?

FYI, I'm using Word 2000!
 
J

Jay Freedman

That's just plain weird. The Chr(13) should become a paragraph mark inside
the text formfield.

You could try this in your code:

Dim temp As String
temp = TextBox1.Text
temp = Replace(temp, Chr(10), "")
temp = Replace(temp, Chr(13), vbCr)
ActiveDocument.FormFields("Text1").Result = temp

The built-in value vbCr is really just a constant that represents a carriage
return (paragraph mark), but maybe forcing the replacement will make Word
happy. If that doesn't work, I'm out of tricks for now.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

jille

Hi Jay,

The vbcr didn't work. I ended up pulling the boxes out using your replace
strings but replaced one with a tilde so that I could do a search & replace
once the text was in the form. It's awkward but I'm happy its solved!.

Thanks for all your help.

Jill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top