【译文】如何从一个表中指定一个控件的值
时 间:2013-09-03 09:04:27
作 者:周芳 ID:24526 城市:上海
摘 要:DLookup 函数用于从指定记录集(一个域)获取特定字段的值。可以在 Visual Basic、宏、查询表达式、窗体或报表上的计算控件中使用 DLookup 函数。
正 文:
来自:微软 翻译:周芳
【译文】如何从一个表中指定一个控件的值
您可以使用DLookup函数来显示字段值不在记录来源表或报告。例如,假设您有一个基于订单详细信息的表。表显示了OrderID、ProductID,UnitPrice、Quantity和Discount字段。 然而,UnitPrice字段是在另一个产品表中。当用户选择一个产品,你可以使用DLookup函数在相同的表计算控制显示UnitPrice。
下面的示例把当前选定的ProductID组合框中产品的价格填入到UnitPrice文本框。
VBA代码
Private Sub ProductID_AfterUpdate()
’在传递给DLookup函数前评估过滤。
strFilter = "ProductID = " & Me!ProductID
’查找产品的单价将它赋值给UnitPrice控件。
Me!UnitPrice = DLookup("UnitPrice", "Products", strFilter)
End Sub
这个DLookup函数有三个参数。第一个参数指定要查找的字段(UnitPrice);第二个指定表(产品);第三个指定找到的值(与ProductID一样的当前记录在订单子表的ProductID值)。
原文:How to: Assign a Control a Value From a Table
You can use the DLookup function to display the value of a field that is not in the record source for your form or report. For example, suppose you have a form based on an order Details table. The form displays the orderID, ProductID, UnitPrice, Quantity, and Discount fields. However, the UnitPrice field is in another table: Products. You could use the DLookup function in a calculated control to display the UnitPrice on the same form when the user selects a product.
The following example populates the UnitPrice text box with the price of the product currently selected in the ProductID combo box.
VBA
Private Sub ProductID_AfterUpdate()
' Evaluate filter before it is passed to DLookup function.
strFilter = "ProductID = " & Me!ProductID
' Look up product's unit price and assign it to the UnitPrice control.
Me!UnitPrice = DLookup("UnitPrice", "Products", strFilter)
End Sub
The DLookup function has three arguments. The first specifies the field you are looking up (UnitPrice); the second specifies the table (Products); and the third specifies which value to find (the value for the record where the ProductID is the same as the ProductID on the current record in the orders subform).
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access选项卡示例】Ac...(09.09)
- 【Access源码示例】按输入...(09.02)
- 【Access日期区间段查询】...(08.29)
- 【Access日期区间段查询】...(08.27)
- Access怎样才能实现日期时...(08.21)
- 【Access定时打开查询】A...(08.19)
- Access生成固定数量的记录...(08.13)
- Access怎样才能实现日期时...(08.12)
- Access利用导航窗体控件对...(08.03)
学习心得
最新文章
- Access表中的字段名、字段标题...(09.19)
- Access快速开发平台--更改“...(09.18)
- 【中秋及国庆优惠】Access培训...(09.15)
- Access如何将日期型的数值转换...(09.14)
- 英文输入法输入数据中存在单引号引起...(09.11)
- 【Access选项卡示例】Acce...(09.09)
- 让Access光标停留在指定的控件...(09.07)
- 关于Access查询条件里使用通配...(09.06)
- Access报表偷懒制作法--Ac...(09.05)
- Access快速开发平台--窗体数...(09.04)