VBA访问/ Word自动化dropdown.listentries错误 [英] VBA Access / Word Automation dropdown.listentries error

查看:108
本文介绍了VBA访问/ Word自动化dropdown.listentries错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码多年来一直运作良好。我最近对.dot文件做了一个无关的更改,现在它不适用于那个。它仍然适用于其他人。



在.dot文件中有一个下拉列表。在VBA修改表单时,表单不受保护。第一行代码清除下拉列表中的条目。下一行调用一个例程,用它填充公司中的人员列表。第三行设置值。再次,这已经很长时间完美无缺。它在Windows 7,Access 2010,Word 2010下运行。它是.dot文件,而不是.dotx文件。因为这是在Windows 7和Access 2010之前创建的,所以它使用.dot文件中的旧表单字段。



 docWord。 FormFields.Item(  CAttn1)。Dropdown.ListEntries.Clear 
调用 subSetAttyDropdowns(docWord.FormFields.Item( CAttn1 ))
docWord.FormFields.Item( CAttn1)。Dropdown.Value = iCAttn







 私人  Sub  subSetAttyDropdowns(oD  As  Word.FormField)

< span class =code-keyword> Dim i 作为 整数
< span class =code-keyword>对于 i = 1 UBound(aAttyNamesForDropdowns)
oD.Dropdown.ListEntries.Add(aAttyNamesForDropdowns(i))
下一步 i

结束 Sub





它在第一行崩溃了。这个错误是无稽之谈。我一直在一遍又一遍。我创建了一个新的.dot文件,其中只有下拉列表,它给了我同样的错误。但是当我运行一个不同的形式,它调用上面相同的例程时,它完美地运行。我重启了很多次。我已经压缩并修复了Access应用程序。



奇怪的是,当我打开.dot文件进行编辑时(作为一个实际的.dot文件,而不是从它创建的.doc文件),它工作良好。所有代码都正确运行,并且.doc文件按预期创建。



这是错误: http://www.oxmyx.com/images/access/WordCrashFromAccess.jpg [ ^ ]



另请注意。当我将相同的代码放入单词.doc文件中的宏时,它也运行良好。我正在用ActiveDocument交换docWord,但它们在这里意味着同样的事情。



我在过去几天里搜遍了所有的解决方案。没有。任何帮助将不胜感激。谢谢。

解决方案

没关系。我找到了一个解决方案,一定是Word中的一个bug。



 设置 docWord = objWord.Documents.Add(Template:= sWordFormsPath& sWordFormFileName&   .dot,Visible:= True)
objWord.Visible = False ' 必须在上面显示,然后设置ojbWord visible = false。如果以上设置为false,则会发生错误。如果此行可见= true,则创建太慢





如果docWord设置为不可见,则代码由于某种原因无法处理下拉列表。但如果它是可见的,但是物体是不可见的,那么它就可以了。感谢微软浪费我的时间。 >:(


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.

解决方案

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

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. >:(


这篇关于VBA访问/ Word自动化dropdown.listentries错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆