Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Form Fields

Status
Not open for further replies.

bbittman

IS-IT--Management
Nov 12, 2008
2
CA
Hi,

Is there a way to write out a value dynamically to the 'active' field on a word form, ie not use the bookmark value?

For instance, I know you can do something like this: ActiveDocument.FormFields("txtEmail").Result = True

But I was hoping that you could do something like this:
ActiveDocument.FormFields(ActiveDocument.ActiveField).Result = True

I have many comboboxes on my document and they all function the same. They need to display more than 25 entries so I followed an example I found and created a dialog box that pops up when entering the field. The dialog has the combo on it and then the user makes their selection, clicks 'Close' and the field on the form gets updated. The problem is I have 20 fields that all work the same way. So I want to reuse the same code and assign the combo selection to the 'active' field. I looked through the properties and methods but nothing jumped out at me. Is there a way to find the active field on a document?

Thanks
Shane
 
Hi Shane,

Presumably your userform is being called via an on-entry macro attached to the formfield. If your formfields have bookmark names (which is the default), then capturing the formfield name (ie bookmark name) with the on-entry macro is a trivial affair. You can then pass the formfield's name and the combo box selection back to the formfield via a sub like:
Code:
Sub UpdateFormField(FFName As String, FFText As String)
ActiveDocument.Bookmarks(FFName).Range.Fields(1).Result.Text = FFText
End Sub
where 'FFName' is your formfield's name and 'FFText' is the string returned by the combo box.

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top