Determine if FormFields exist in Microsoft Word Merge

A

ajbarilla

I have a database that merges several Microsoft Word documents using
data from Microsoft Access based on the user's selection. The
problem that I am running into is that the documents have either all
formfields or all bookmarks for the merged data. The documents with
form fields have data in the fields (ie insert name here) that I want
to replace with the merge. If I use the following code to merge
formfields:

oDoc.FormFields(MergeField).Result = Me(TxtBox)

I get an error if the document has bookmarks and not mergefields.
If I use the following code for bookmarks:

oDoc.bookmarks(MergeField).range.insertafter Me(TxtBox)

It works for the documents with bookmarks. I dont get an error but
it inserts the data after the formfield and doesnt replace it. I
guess it treats it as a bookmark. I know I can use the following
code to determine if there are bookmarks in the document:

If oDoc.Bookmarks.Exists(MergeField) = True

But it treats the formfields as bookmarks and I get the same problem
as above. My question is: Is if there is a way to determine if
there are formfields in a document in code so I can fix these
errors? Thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top