Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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.

VB
docWord.FormFields.Item("CAttn1").Dropdown.ListEntries.Clear
Call subSetAttyDropdowns(docWord.FormFields.Item("CAttn1"))
docWord.FormFields.Item("CAttn1").Dropdown.Value = iCAttn



VB
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.
Posted
Updated 31-Aug-14 5:51am
v5

1 solution

Never mind. I found a solution to this, what must be a bug in Word.

VB
Set docWord = objWord.Documents.Add(Template:=sWordFormsPath & sWordFormFileName & ".dot", Visible:=True)
objWord.Visible = False 'must make visible above and then set ojbWord visible = false. if above is set false, errors occur. if this line is visible = true, then create is too slow


If the docWord is set to invisible, the code can't deal with the dropdown for some reason. But if it's visible, but the objWord is invisible, then it works. Thanks Microsoft for wasting my time with this one. >:(
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900