View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Word Field Type - Fill In Prompt Problem (Word Insert Field in .NE

Try something like the following (I leave you to get the syntax right)

object fieldType = Word.WdFieldType.wdFieldEmpty;
object fieldText1 = ""
object fieldText2 = " FILLIN \"" + "SOME TEXT" + "\" \\d \"" + "SOME DEFAULT
VALUE" + "\" ";
object preserveFormatting = true;
object newField = wd.Fields.Add(wd.Application.Selection.Range, ref
fieldType, ref fieldText1, ref preserveFormatting);
newField.Code.Text = fieldText2;

Personally, I would set preserveFormatting = false as it just makes the
field unnecessarily complex (unless you know you need it, of course).

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Evan Putranto" wrote in message
...
Hi,

Before I start please forgive me if I am posting this on the wrong
discussion.

Currently I am working on trying to use Microsoft Word 2007 as a control
in
windows form.

Basically I use this http://www.codeproject.com/office/WordInDotnet.asp
code
as a base.

As part of the requirement is the user has to be able to add a Field with
type of Fill In.


I have manage to do that by using this code:

************************************************** *********
Document wd = objWinWordControl.document;

object fieldType = Word.WdFieldType.wdFieldFillIn;

object fieldText = "\"" + "SOME TEXT" + "\" \\d \"" + "SOME DEFAULT VALUE"
+
"\"";

object preserveFormatting = true;

wd.Fields.Add(wd.Application.Selection.Range, ref fieldType, ref
fieldText,
ref preserveFormatting);

bla.ShowCodes = false;

************************************************** *********

The only problem is whenever the code try to add the fields it prompts the
user asking what value it should have.

Surely it will have "SOME DEFAULT VALUE" in the message box and the user
just have to click OK but it still annoy the user.

So this is the 1st question:
Is there any way to prevent the program prompting the user?

If that can't be done then this 2nd problem will be relevant.

It seems that whenever a fill-in field added, during the prompt being
shown
to the user, the form seems to always lost focus (with the 1st being the
exception), so this is only happening for the 2nd, 3rd and 4th field and
so
on.

Just to make it clear whenever this code get executed:
wd.Fields.Add(wd.Application.Selection.Range, ref fieldType, ref
fieldText,
ref preserveFormatting);
The whole program always lost focus.

So if there is a way to prevent the program prompting the user then the
2nd
problem will no longer be relevant.


I would really appreciate if some one can help me with this.
Thank you in advance for any help.