Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Evan Putranto Evan Putranto is offline
external usenet poster
 
Posts: 6
Default Word Field Type - Fill In Prompt Problem (Word Insert Field in .NE

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.

  #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.


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Evan Putranto Evan Putranto is offline
external usenet poster
 
Posts: 6
Default Word Field Type - Fill In Prompt Problem (Word Insert Field in

Hi Peter,

Thank you for your reply. It does help me. However by doing it that way it
lost a very important functionality.

We need "SOME DEFAULT VALUE" to appear when the toggle show codes activated
(when it is false).

By doing it your way the fill in is perfect but the value is just an empty
string.

Regards,
Evan
  #4   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

If the "SOME DEFAULT VALUE" text is not being inserted in the Empty filed,
can you please check your string syntax (I'm using VBA here and do it a
slightly different way, but it works OK he

f.Code.Text = " fillin " & Chr(34) & "title" & Chr(34) & "\d " & Chr(34) &
"SOME DEFAULT VALUE" & Chr(34) & " "


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

"Evan Putranto" wrote in message
news
Hi Peter,

Thank you for your reply. It does help me. However by doing it that way it
lost a very important functionality.

We need "SOME DEFAULT VALUE" to appear when the toggle show codes
activated
(when it is false).

By doing it your way the fill in is perfect but the value is just an empty
string.

Regards,
Evan


  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Evan Putranto Evan Putranto is offline
external usenet poster
 
Posts: 6
Default Word Field Type - Fill In Prompt Problem (Word Insert Field in

Hi Peter,

I think you got me wrong. The field is correctly displayed as
{FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE"}

However when I do right click and then "Toggle Field Codes", the "SOME
DEFAULT VALUE" text does not appear. It is just an empty string.

While previously when using the standarised way (wdFieldFillIn) "SOME
DEFAULT VALUE" is there (assuming the user click OK on the prompt).

Regards,
Evan


  #6   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

However when I do right click and then "Toggle Field Codes", the "SOME
DEFAULT VALUE" text does not appear. It is just an empty string.


Understood.

At the end of the existing code, try

newField.Result.Text = "SOME DEFAULT VALUE";

(or whatever the correct syntax is for your language)

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

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

I think you got me wrong. The field is correctly displayed as
{FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE"}

However when I do right click and then "Toggle Field Codes", the "SOME
DEFAULT VALUE" text does not appear. It is just an empty string.

While previously when using the standarised way (wdFieldFillIn) "SOME
DEFAULT VALUE" is there (assuming the user click OK on the prompt).

Regards,
Evan


  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Evan Putranto Evan Putranto is offline
external usenet poster
 
Posts: 6
Default Word Field Type - Fill In Prompt Problem (Word Insert Field in

Hi Peter,

Thank you again for your help.

This is the result that I get with the toggle show codes = false:

SOME DEFAULT VALUE

However this is the result with the toggle show codes = true:

{ FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE" } SOME DEFAULT VALUE

It looks like it inserted the text after the fill-in field not in the
fill-in field.

I have tried to use Result.InsertAfter, Result.InsertBefore,
Result.InsertCaption and still have no luck.

Regards,
Evan
  #8   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

Hi Evan,

I think the only thing that is likely to work is to ensure that field code
display is in the state you need. Right now I can't check the code you need
if you want to save the existing settings and switch back but it would be
something like the following in VBA

Dim bShowFieldCodes As Boolean
bShowFieldCodes = ActiveWindow.View.ShowFieldCodes
ActiveWindow.View.ShowFieldCodes = False ' or True
' do your stuff here
ActiveWindow.View.ShowFieldCodes = bShowFieldCodes


--
Peter Jamieson


"Evan Putranto" wrote:

Hi Peter,

Thank you again for your help.

This is the result that I get with the toggle show codes = false:

SOME DEFAULT VALUE

However this is the result with the toggle show codes = true:

{ FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE" } SOME DEFAULT VALUE

It looks like it inserted the text after the fill-in field not in the
fill-in field.

I have tried to use Result.InsertAfter, Result.InsertBefore,
Result.InsertCaption and still have no luck.

Regards,
Evan

  #9   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Evan Putranto Evan Putranto is offline
external usenet poster
 
Posts: 6
Default Word Field Type - Fill In Prompt Problem (Word Insert Field in

Hi Peter,

Thx for your reply. I know what you mean.
This is what I need Peter using vb syntax:

During

ActiveWindow.View.ShowFieldCodes = True

The following will be shown:
{ FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE" }

During

ActiveWindow.View.ShowFieldCodes = False

The following will be shown:
SOME DEFAULT VALUE

But I need to achieve this without prompting the user.
Is that possible?

Currently during

ActiveWindow.View.ShowFieldCodes = True

it shows

{ FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE" } SOME DEFAULT VALUE

Thank you again for your help.

Regards,
Evan
  #10   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

Yes, I could have sworn you could make it work that way. But maybe not.

Anyway, I think the following will give you what you need except you may
need to set the field code view how you want it at the end:

Sub insfillin()
Dim f As Field
Const sPromptText = "SOME TEXT"
Dim strDefaultText As String
strDefaultText = Chr(34) & "SOME DEFAULT VALUE" & Chr(34)
Set f = ActiveDocument.Fields.Add(Selection.Range, wdFieldQuote,
strDefaultText, False)
' you should not need the next line...
'f.Update
f.Code.Text = " FILLIN " & Chr(34) & sPromptText & Chr(34) & "\d " &
strDefaultText & " "
End Sub


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

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

Thx for your reply. I know what you mean.
This is what I need Peter using vb syntax:

During

ActiveWindow.View.ShowFieldCodes = True

The following will be shown:
{ FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE" }

During

ActiveWindow.View.ShowFieldCodes = False

The following will be shown:
SOME DEFAULT VALUE

But I need to achieve this without prompting the user.
Is that possible?

Currently during

ActiveWindow.View.ShowFieldCodes = True

it shows

{ FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE" } SOME DEFAULT VALUE

Thank you again for your help.

Regards,
Evan




  #11   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Evan Putranto Evan Putranto is offline
external usenet poster
 
Posts: 6
Default Word Field Type - Fill In Prompt Problem (Word Insert Field in

Hi Peter,

That works. Thank you very much for your help. I really appreciate it.

Regards,
Evan

"Peter Jamieson" wrote:

Yes, I could have sworn you could make it work that way. But maybe not.

Anyway, I think the following will give you what you need except you may
need to set the field code view how you want it at the end:

Sub insfillin()
Dim f As Field
Const sPromptText = "SOME TEXT"
Dim strDefaultText As String
strDefaultText = Chr(34) & "SOME DEFAULT VALUE" & Chr(34)
Set f = ActiveDocument.Fields.Add(Selection.Range, wdFieldQuote,
strDefaultText, False)
' you should not need the next line...
'f.Update
f.Code.Text = " FILLIN " & Chr(34) & sPromptText & Chr(34) & "\d " &
strDefaultText & " "
End Sub


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

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

Thx for your reply. I know what you mean.
This is what I need Peter using vb syntax:

During

ActiveWindow.View.ShowFieldCodes = True

The following will be shown:
{ FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE" }

During

ActiveWindow.View.ShowFieldCodes = False

The following will be shown:
SOME DEFAULT VALUE

But I need to achieve this without prompting the user.
Is that possible?

Currently during

ActiveWindow.View.ShowFieldCodes = True

it shows

{ FILLIN "SOME TEXT" \d "SOME DEFAULT VALUE" } SOME DEFAULT VALUE

Thank you again for your help.

Regards,
Evan



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Merge Field problem with Word-Mail Merge from Excel documen Augusta E. Microsoft Word Help 2 June 20th 05 10:59 AM
Mail merge field different in datasource & insert a field menu Silvs Mailmerge 1 April 22nd 05 06:18 AM
Can I insert some type of field into a Word form that allows the . [email protected] Microsoft Word Help 3 March 31st 05 07:50 AM
Prompt user to fill in drop down field when document opens DGjr. Microsoft Word Help 1 February 28th 05 09:13 PM
Fill-in field - returning to a previous field. Lorrie Mailmerge 1 December 13th 04 08:39 PM


All times are GMT +1. The time now is 03:36 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"