简体   繁体   English

MSAccess VBA编码中的更改

[英]Changes in MSAccess VBA coding

I have been coding in MSAccess since the Win95 days. 自Win95以来,我一直在使用MSAccess进行编码。 Over the years, these apps have been upgraded to the latest versions of MSAccess. 多年来,这些应用程序已升级到最新版本的MSAccess。 I am guessing that the change occurred sometime after Access 2003. 我猜想该更改是在Access 2003之后的某个时候发生的。

I am sure that this is a trivial question, but I can't seem to find the answer in the documentation online. 我敢肯定这是一个琐碎的问题,但是我似乎无法在在线文档中找到答案。

In the old days, my Modules would look like this: 在过去,我的模块如下所示:

    Option Compare Database

    Private Sub PrintReports_Click()
    Dim db As Database
    Dim rs As Recordset
        Set db = CurrentDb
        Set rs = db.OpenRecordset("Classes", dbOpenDynaset)
...

Where Classes is usually a table or query in my database. “类”通常是数据库中的表或查询。 This continues to work in older databases that have been converted to the latest version. 这在已转换为最新版本的较旧数据库中仍然可以使用。

When I try to create a new database using the above code, I get error 13, type mismatch error, with no explanation of what is wrong and how to fix it. 当我尝试使用上述代码创建新数据库时,出现错误13,键入不匹配错误,没有解释什么是错误以及如何修复它。

So 2 questions: Why does it work on old databases but not newly created ones, and what is the correct way to open and refer to my tables in my VBA code? 所以有两个问题:为什么它不能在旧数据库上工作,而不能在新创建的数据库上工作?在VBA代码中打开和引用我的表的正确方法是什么?

Thanks for your help, Dan 谢谢您的帮助,丹

尝试检查“参考”,是否缺少任何内容,还请按以下方式声明db

Dim db As DAO.Database 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM