This project has moved and is read-only. For the latest updates, please go here.

Adding wdFieldFormTextInput

Apr 3, 2014 at 8:52 AM
Edited Apr 3, 2014 at 1:49 PM
Hi, while I'm able to add a Merge Field this way:
        Dim s As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
        Dim objFieldName As Object = s.Tag
        Dim myFormfield As Word.Field
        myFormfield = oWord.Selection.Fields.Add(range:=oWord.Selection.Range, type:=WdFieldType.wdFieldMergeField, text:=objFieldName)
I'd like to add a Form text input but I can't get it to work :
myFormfield = oWord.Selection.Fields.Add(range:=oWord.Selection.Range, type:=WdFieldType.wdFieldFormTextInput, text:=objFieldName)

ps: the myFormfield .Result = "sometext" is not working, it says it requires a range!

Could you please help me?
Thank you

ok solved
        Dim myFormfield As Word.FormField
        myFormfield = oWord.ActiveDocument.FormFields.Add(oWord.Selection.Range, WdFieldType.wdFieldFormTextInput)
        myFormfield.Name = Variabile.Cod
        myFormfield.Result = Variabile.Description
Apr 7, 2014 at 12:14 PM
"I can't get it to work " is not realy helpful. Please spend more exception details in order to anaylze the problem.
I want reproduce the problem. Do me a pleasure and try o use it without named argmuents in the the Add method.(you may reach a wrong method oberload, not sure yet..)

*Sebastian
Apr 9, 2014 at 9:07 PM
Thank you Sebastian, I finally made it!
Even if I prefer C# I had to write it in Vb.net:

This works like a charm:
Private oWord As Word.Application
......
                    myFormfield = oWord.ActiveDocument.FormFields.Add(oWord.Selection.Range, WdFieldType.wdFieldFormTextInput)
                    myFormfield.Name = Variabile.Codice & "_" & value.ToString("00")
                    myFormfield.Result = Variabile.Descrizione
                    oWord.Selection.MoveRight(1)
Thank You