unlink fields in a Word document from Access VBA

T

Todd

I have code that creates a Word document and, based on several criteria,
uses includetext fields to bring in data from several other files. That all
works perfectly. Next, I need the code to "unlink" the fields so that the
document becomes static (doesn't rely other files anymore). I know how this
code should look like in Word's VBA, but I'm not sure how to get it to work
from Access. Here is how the code would look in Word...

-------------------Beginning Code----------------
'Unlink fields to make document static (except for TOC)
Dim rngDoc As Range
Dim F As Field
Dim oDoc As Document
Dim aTOC As TableOfContents
For Each rngDoc In oDoc.StoryRanges
For Each F In rngDoc.Fields
If F.Type = wdFieldIncludeText Then
F.Unlink 'Unlinks INCLUDETEXT fields only...
End If
Next F
While Not (rngDoc.NextStoryRange Is Nothing)
Set rngDoc = rngDoc.NextStoryRange
For Each F In rngDoc.Fields
If F.Type = wdFieldIncludeText Then
F.Unlink 'Unlinks INCLUDETEXT fields only...
End If
Next F
Wend
Next rngDoc
--------------------Ending Code--------------------


Here is the code I'm using to start the Word doc...

-------------------Beginning Code----------------
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
With objWord
.........
End with
--------------------Ending Code--------------------

Thanks in advance for your help!!!
 
A

Albert D. Kallal

I have a nice working sample that does a merge of the current record to
word.

After the word merge is done, the resulting document is free of bookmarks
and fields.

So, it should be ideal for your needs.

The sample I have can be found here:
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html

what is nice/interesting about my sample is that is specially designed to
enable ANY form with ONE LINE of code....

Thus, each time you build a new form, you can word merge enable it with
great ease.
 
T

Todd

That is a very nice bit of code. Great work! Because of the project I'm
working on though, I'm still need to try and get this "unlink" code to work.
I'm definitely going to try and use your code in future projects, however.
Again, great job!

Can anyone help with this code? Thanks!
 

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