ms word - FormField.Add method does not return a reference to the new field (bug?) -


i using word 2010 create electronic form there appears bug in add method of formfield collection; want know if there way around it.

in form have table, asking information staff members, allows additional rows added pressing button. code adds new row table goes through each cell in new row creating form fields.

private sub addstaffrow(t table)      dim rownum integer     dim ff formfield      ' add new row     t.rows.add     rownum = t.rows.count      ' insert form fields in cells     ' staff role dropdown     set ff = activedocument.formfields.add(t.cell(rownum, 1).range, wdfieldformdropdown)     ff.name = "staff_role" & rownum     ff.dropdown.listentries         .add "principle investigator"         .add "sub investigator"         .add "research nurse"         .add "practice nurse"         .add "administrator"                 end      ' staff name textbox     set ff = activedocument.formfields.add(t.cell(rownum, 2).range, wdfieldformtextinput)     ff.name = "staff_name" & rownum      ' gcp certificate available     set ff = activedocument.formfields.add(t.cell(rownum, 3).range, wdfieldformdropdown)     ff.name = "staff_gcp" & rownum     ff.dropdown.listentries         .add "yes"         .add "no"         .add "na"     end end sub 

the fist field added works correctly, dropdown created , named options added. however, when next field added formfield collection count increments, field appears in document, reference returned function first field (the staff role dropdown)

the documentation states return value (supposed be) reference formfield object added collection:

ms-word vba documentation snippet

the returned reference incorrect because after code has completed first dropdown field has name of last field added , looks this

enter image description here

am doing wrong or there way around "bug"?

unfortunately, have ensure range not include end-of-cell range marker before inserting formfield.

e.g.

dim r word.range set r = t.cell(rownum,1).range r.setrange r.start, r.end-1 set ff = activedocument.formfields.add(r, wdfieldformdropdown) 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -