Access Text Control To Word Formfield

P

Pete

The following is a method to post data to a word form field from vba.
However, how do you split up a text string variable if it contains
carriage returns? When I run the following code it works but it
imports the text in one line with little boxes which are actually
carriage returns (chr(10) or chr(13)). What I would like to do is
create a loop to search for the line feeds and append a portion of the
string at a time to the formfield. If anyone has a better idea I am
all ears.



objWord.ActiveDocument.FormFields(BookMarkName).Result = FieldValue
 
J

Jonathan Parminter

Pete said:
-----Original Message-----
The following is a method to post data to a word form field from vba.
However, how do you split up a text string variable if it contains
carriage returns? When I run the following code it works but it
imports the text in one line with little boxes which are actually
carriage returns (chr(10) or chr(13)). What I would like to do is
create a loop to search for the line feeds and append a portion of the
string at a time to the formfield. If anyone has a better idea I am
all ears.



objWord.ActiveDocument.FormFields(BookMarkName).Result = FieldValue
.

Hi Pete,

use the following as an example

***** code starts ****

Dim ctl As Control
Dim astrText() As String
Dim intIndex As Integer

Set ctl = FieldValue
astrText = Split(ctl.Value, Chr(13) & Chr(10))

For intIndex = 0 To UBound(astrText())
MsgBox astrText(intIndex)
DoEvents
Next intIndex

**** code ends ****

Luck
Jonathan
 
P

Pete

Thanks a million. That's a good technique and it works but.... The
formfield doesnot allow multiple lines. I can only assign it a value.
Which means everytime I split the lines up each time the loop
executes, it overwrites the previous line. I then used InsertAfter
and it works great but that doesn't put the text in the formfield. At
this point I'm still scratching my head but I do appreciate your code
and I will use it until I can resolve the problem. Thanks
 
J

Jonathan Parminter

Pete said:
-----Original Message-----
Thanks a million. That's a good technique and it works but.... The
formfield doesnot allow multiple lines. I can only assign it a value.
Which means everytime I split the lines up each time the loop
executes, it overwrites the previous line. I then used InsertAfter
and it works great but that doesn't put the text in the formfield. At
this point I'm still scratching my head but I do appreciate your code
and I will use it until I can resolve the problem. Thanks
.

Hi Pete, I recommend posting word related questions (such
as multiline form fields) to the word usergroup. However,
in testing, a form field does seem to allow more than one
line of text (each line separated with a paragraph marker).

Luck
Jonathan
 
P

Pete

I finally got it!!!! Replace vbCrLf with vbVerticalTab as "Astrid"
mentions below. Thank God for usenet. Now I will rest well.

From: Astrid ([email protected])
Subject: Re: Inserting multiple paras in a formfield

View this article only
Newsgroups: microsoft.public.word.word97vba
Date: 2000/05/19

Hi Bill,

vbVerticalTab is the constant for chr(11). I know the helpfile says
it's not
useful in Windows but I've used it many times in former projects in
W97. For
example for splitting up the content of a multiline textbox in a
userform
with new line signs instead of with paragraph marks (when working with
styles). Never had any trouble with it.
But, to come back to your question, I don't know where it's originally
meant
for. Maybe somebody else does?
 

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