简体   繁体   English

DLookup:MS Access VBA中的查询与表?

[英]DLookup: query vs. table in MS Access VBA?

What is the difference between these two lines of code in MS Access VBA. MS Access VBA中的这两行代码有什么区别? does it really make a difference? 真的有什么不同吗?

Facts: 事实:

  1. tblLogin is a linked table tblLogin是一个链接表
  2. qryA is = tblLogin.* qryA是= tblLogin。*

- --

DLookup("EmployeeID", "qryA", "[EmployeeID]=" & Me.empID) & "" = ""

vs

DLookup("EmployeeID", "tblLogin", "[EmployeeID]=" & Me.empID) & "" = ""

are there any restrictions that makes us want to go create a query identical to a table? 是否有任何限制使我们想要创建与表相同的查询?

In DLookup? 在DLookup中? I've never encountered a difference. 我从未遇到过任何不同。 Pretty sure performance is the same. 可以肯定的是性能是相同的。 The advantages I can think of to using a query are unrelated to performance: 我可以想到的使用查询的优势与性能无关:

  • Simplicity: if, for example, you later decide to have something like an "Active" flag in the table, and you want everything that references the table to filter out "inactive" records, you can just change the query. 简单性:例如,如果您以后决定在表中添加类似“活动”标志的内容,并且希望引用该表的所有内容都可以过滤掉“非活动”记录,则只需更改查询即可。
  • Security: this is more if the tables are in a linked server, but you may not want to reference the tables directly. 安全性:如果表位于链接服务器中,则更为有效,但是您可能不想直接引用这些表。

First of all, your question should say that you mean using DLookUp . 首先,您的问题应该说您的意思是使用DLookUp

Second, in the case of DLookup, no, there is no difference. 其次,在DLookup的情况下,没有区别。

But to be honest, just in that case. 但老实说,就是在这种情况下。 Queries are, with no doubt, more helpful to work with. 毫无疑问,查询会更有用。 Queries allow you to call for data in the way you want, sorted, with different parameters, grouping data (even from different tables). 通过查询,您可以以所需的方式调用数据,并使用不同的参数对数据进行分组(甚至来自不同的表)。

To make it really simple, a table is like a store, where you save your goodies, and the query would be like a smart worker that gets for you in seconds the info the customer needs (or the boss), and this worker can adapt to any need. 简单地说,表就像商店,您可以在其中保存好吃的东西,查询就像一个聪明的工作人员,可以在几秒钟内为您提供客户(或老板)所需的信息,并且该工作人员可以适应任何需要。

That's my POV, anyways. 无论如何,那是我的观点。

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

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