Fix Error 438 When Updating a Word Table of Contents with VBA
Question details
Update a Word table of contents from Access VBA using late binding without triggering error 438.

- Product
- Microsoft Word and Microsoft Access VBA
- Device & OS
- not provided
- Scenario
- An Access macro automates Word and updates a table of contents in a merged document.
- Observed behavior
- The update raises error 438 when the code uses an incorrect collection name or object reference.
Confirm that the merged Word document contains a table of contents and identify the VBA variable that refers to that document, rather than the Word application. In Access, open the relevant module in the VBA editor to inspect the update code.
Update the merged document's TablesOfContents collection
Use this approach when Access raises error 438 while updating a Word table of contents through a late-bound document object.
The Word document collection is named TablesOfContents, with an s after Table and Contents. The update call must be made on the merged document object, not on the Word application.
In the Access VBA editor, locate the variable that refers to the merged Word document. The following steps assume it is named oWord and is declared As Object for late binding.
Replace the incorrect collection reference with: oWord.TablesOfContents(1).Update. This updates the first table of contents in the document.
If the code uses With oWord, call .TablesOfContents(1).Update inside that block. Remove an incorrect .oWord reference inside the block, because it attempts to access a member of the document rather than the variable itself.
If the document may not contain a table of contents, check its collection first: If oWord.TablesOfContents.Count > 0 Then oWord.TablesOfContents(1).Update. Run the Access procedure again and verify the updated contents in Word.

Work with Word documents in WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. It can help you move everyday document work to WPS, although it does not fix Microsoft Word VBA errors and macro compatibility should be tested separately.

Frequently Asked Questions
Why does the table of contents update raise error 438?
Error 438 can occur if the code uses an unsupported member name or calls the collection on the wrong object. Check that the name is TablesOfContents and that the variable refers to the Word document.
How do I update the first table of contents with late binding?
With a document variable named oWord declared As Object, use oWord.TablesOfContents(1).Update. Ensure that oWord refers to the merged document and that the document contains a table of contents.
What should I write inside With oWord?
Use .TablesOfContents(1).Update inside the With oWord block. A reference such as .oWord attempts to access an oWord member of the object and is not needed to refer to the variable.
How can I avoid updating a table of contents that does not exist?
Check oWord.TablesOfContents.Count before using index 1. If the count is zero, insert a table of contents in Word or adjust the automation to create one before updating.




