DLOOKUP在测试数据库中工作,但不在实际数据库中工作 [英] DLOOKUP works in test database, but not in real one

查看:62
本文介绍了DLOOKUP在测试数据库中工作,但不在实际数据库中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了一个测试数据库,该数据库从Products表中查找产品信息,以通过表单填充Sales表中的字段。在测试数据库中,我输入产品编号,并显示项目描述和价格(我使用DLOOKUP执行此操作)。当我手动将代码复制到真实数据库时,输入的产品ID并不重要,只有Products表中的第一项填充了Item描述和Price字段。在这两个数据库中,我在After Update事件下使用了VBA。我打开了两个VBA文件,它们看起来完全一样。为什么一个工作而另一个工作呢?除了DLOOKUP之外还有更好的方法来做同样的事情吗?

I ran a test database that looks up product information from the Products table to populate fields in the Sales table through a form. In the test DB, I enter the product number, and the item description and price appear(I used DLOOKUP to do this). When I manually copy the code over to the real DB, it doesn''t matter what product ID I type in, only the first item in the Products table populates the Item description and Price fields. On both databases, I used VBA under the After Update event. I have opened both VBA files and they look exactly the same. Why does one work and the other doesn''t? Is there a better way to do the same thing besides DLOOKUP?

推荐答案

请发布你正在使用的代码。
Kindly Post the code that you are using.


Private Sub ProductID_AfterUpdate()

ProductName = DLookup(" ProductName"," PriceList"," [ProductID] ="& ProductID)

Profit = DLookup (Profit,PriceList,[ProductID] = &&;& ProductID)

Price = DLookup(Price,PriceList,[ProductID] ="& ProductID)

Tax = DLookup(Tax,PriceList,[ProductID] ="& ProductID)

End Sub


表单中的所有字段都是文本框。我在ProductID文本框中放入的产品ID无关紧要,显示相同的产品名称,利润,价格和税。我还记得,它工作的那个有ProductID作为一个组合框,它链接到ProductID和ProductName,但它只显示ProductName。这是区别,组合框与文本框?
Private Sub ProductID_AfterUpdate()
ProductName = DLookup("ProductName", "PriceList", "[ProductID] =" & ProductID)
Profit = DLookup("Profit", "PriceList", "[ProductID] =" & ProductID)
Price = DLookup("Price", "PriceList", "[ProductID] =" & ProductID)
Tax = DLookup("Tax", "PriceList", "[ProductID] =" & ProductID)
End Sub

All fields in the form are text boxes. It doesn''t matter what product ID I put in the ProductID text-box, the same product name, profit, price and tax shows up. I also just remembered, the one where it works has the ProductID as a combo box that is linked to both the ProductID and ProductName, but it just shows the ProductName. Is that the difference, combo-box vs. text-box?


就个人而言,我会在组合框的行源中包含所有5个字段,隐藏选择性字段,然后导出相应的用户根据列号选择产品后的值。我创建了一个包含所有Fields的Demo,只显示[ProductName]字段(按字母顺序排序),同时隐藏其他Fields(Columns)。选择值后,其他字段将被推送到相应的文本框。这种方法基本上是万无一失的,因为不存在Typos,并且可以选择的唯一值是PriceList表中的值(LimitToList = Yes)。下载附件以查看我所指的内容。





Personally, I would include all 5 Fields in the Row Source of the Combo Box, hide selective Fields, then derive the appropriate Values once the User has selected a Product based on the Column Number. I created a Demo that includes all the Fields, displays only the [ProductName] Field (sorted alphabetically), while hiding the other Fields (Columns). Once a Value is selected, the other Fields are pushed to the appropriate Text Boxes. This approach is essentially foolproof, since there can be no Typos, and the only Values that may be selected are those in PriceList Table (LimitToList = Yes). Download the Attachment to see what I am referring to.
附加文件
DLookup.zip (21.2 KB,104 views)
Attached Files
DLookup.zip (21.2 KB, 104 views)


这篇关于DLOOKUP在测试数据库中工作,但不在实际数据库中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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