This code has been working perfectly for years. I recently made an unrelated change to a .dot file and now it doesn't work with that one. It still works with others.
In the .dot file there is a dropdown. The form is not protected while VBA is modifying it. The first line of code clears the entries in the dropdown. The next line calls a routine that populates it with a list of people in the company. The third line sets the value. Again, this has worked flawlessly for a long time. It's running under Windows 7, Access 2010, Word 2010. It's a .dot file, not a .dotx file. Because this was created long before Windows 7 and Access 2010, it's using the legacy form fields in the .dot file.
docWord.FormFields.Item("CAttn1").Dropdown.ListEntries.Clear
Call subSetAttyDropdowns(docWord.FormFields.Item("CAttn1"))
docWord.FormFields.Item("CAttn1").Dropdown.Value = iCAttn
Private Sub subSetAttyDropdowns(oD As Word.FormField)
Dim i As Integer
For i = 1 To UBound(aAttyNamesForDropdowns)
oD.Dropdown.ListEntries.Add (aAttyNamesForDropdowns(i))
Next i
End Sub
It crashes on the first line. The error is nonsense. I've been over and over and over this. I've created a new .dot file with only the dropdown list in it and it gives me the same error. But when I run a different form, which calls the same routines above, it works perfectly. I've rebooted many times. I've compacted and repaired the Access application.
The odd thing is that when I have the .dot file open for editing (as an actual .dot file, not a .doc file created from it), it works fine. All the code runs correctly and the .doc file is created as expected.
Here's the error:
http://www.oxmyx.com/images/access/WordCrashFromAccess.jpg[
^]
Another note. When I put the same code into a macro in a word .doc file, it runs fine as well. I'm exchanging "docWord" with "ActiveDocument" but they mean the same thing here.
I've searched all over for a solution in the last few days. Nothing. Any help would be greatly appreciated. Thanks.