PDA

View Full Version : Conditional insert of document into Word form field



conner
07-19-2007, 07:52 AM
TIA for the help. I will try to provide too much information up front in anticipation of questions.

I have a form for job descriptions. It has a field named Level (fourth in the form) with 6 levels in a dropdown list: Analyst, Consultant, Sr. Consultant, Manager, etc. Based on the value of this field, I need to select one of six Word documents and insert it into a field called cornerstones (located at the endof the form, last field, #17). I can do this, once. The issue is that I recognize that the person completing the form may accidentally tab through the level field and not mean to select the default or may select incorrectly, or we may reuse a base job description, which means the value of cornerstones needs to change.

This is where everything breaks for me. After I have inserted the document into the field, the filed is replaced by the document, and I can no longer clear the contents.

Here is my high level logic:
Determine value of level field
Clear the contents of the cornerstones field
Locate to the cornerstones field
Select the proper document to insert into the cornerstones field
Insert the document into the cornerstones field
Locate to the next field, travel


I have tried this many ways using various incantations of Selection.InsertFile FileName, but nothing works.

Any help will be appreciated (and possibly rewarded with a shirt).

Regards,

Ben

fumei
07-19-2007, 07:58 AM
Use a bookmark instead.

conner
07-19-2007, 08:32 AM
How would I do this programmatically? I can go to the bookmark, but the insertion process replaces the flied with the document making it impossible to perform the operation a second time.

fumei
07-20-2007, 02:02 AM
Try the attached. The FillABookmark procedure can be executed by clicking "Test Bookmark" on the top toolbar.

The range that is bookmarked is the existing text "something".

Clicking "Text Bookmark" will display an Inputbox. Type something.....anything, and hit Enter. Or, if you are one of those weird people that remove their hands from the keyboard to click the OK button...click the OK button. However, typing some text and hitting Enter does the job.

The text "something" will be replaced by whatever text you entered. You can do this as many times as you like. The bookmark text content is infinitely replaceable.

fumei
07-20-2007, 02:08 AM
BTW:
I can go to the bookmark, but the insertion process replaces the flied with the document making it impossible to perform the operation a second time.I suspect that you are making reference to formfields as bookmarks. They are listed as Bookmarks, and you can make reference to them as bookmarks. But frankly, it is better NOT to.

Say you have a formfield named "Whatever". If you replace its contents (by referencing it as a formfield ie. .Result) you can repeat this as many times as you like.

Formfields("Whatever").Result = "some string" will also replace a text formfield content (Result), any number of times.

If you reference it as a bookmark....you can not.